react-recipes
Version:
A React Hooks utility library containing popular customized hooks
28 lines (20 loc) • 598 B
Markdown
Makes `setInterval` way easier
- `callback: Function`: Callback after each interval
- `delay: Number`: delay time between each callback invocation
- `runOnLoad?: Bool`: Whether or not to run interval on mount, default is false.
- `effectDependencies?: Array`: List of effects to re-call callback, default is `[]`.
```js
import { useInterval } from "react-recipes";
const App = () => {
// Grabs user data every 7500ms or when user changes
useInterval(() => {
if (user) {
getUserInfo(user);
}
}, 7500, true, [user]);
...
};
```