Reactive hook task, executes task after timeout.
npm install react-task-z

!Downloads
---
---
+ react task
+ support task runner with timeout.
install via npm:
```
npm i react-task-z
| Property | Data Type | Default Value | Property Unit |
| :---------: | :---------------: | :------------: | :-----------: |
| callback | callback/promise | func | |delay
| | number | 0 | ms |maxLoop
| | number | 0 | - |immediate
| | boolean | false | - |
#### Guilde
`js
/**
+ run/stop
// ver>=1.1.0
task.run(); // run immediate
task.stop();
task.runAfter() // run after delay
+ maxLoop
maxLoop = 0: infinite
maxLoop > 0: limit
+ delay: run after 1 period of time
*/
`
##### sync function
`js
import useTask from 'react-task-z';
// with basic
const task = useTask({
delay: 4000,
maxLoop: 3,
// immediate: true,
callback: (loopTime, isLast) => {
console.log(loopTime, isLast);
// isLast => it will stop automatically
// if (isLast) {
// TODO something
// }
},
});
// ver>=1.1.0
task.run(); // run immediate
task.stop();
task.runAfter() // run after delay
`
##### async function
`js
import useTask from 'react-task-z';
const task = useTask({
delay: 4000,
maxLoop: 3,
callback: async (loopTime, isLast) => {
console.log(loopTime, isLast);
const results = await fetch('https://jsonplaceholder.typicode.com/todos/1')
const info = await results.json();
console.log("Fetch called!");
// isLast => it will stop automatically
// if (isLast) {
// TODO something
// }
},
});
// ver>=1.1.0
task.run(); // run immediate
task.stop();
task.runAfter() // run after delay
``
MIT