1.1.2 • Published 11 months ago

react-task-z v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

  • react task
  • support task runner with timeout.

Installation

install via npm:

npm i react-task-z

Usage

Available properties

PropertyData TypeDefault ValueProperty Unit
callbackcallback/promisefunc
delaynumber0ms
maxLoopnumber0-
immediatebooleanfalse-
startingbooleanfalseno-used

Guilde

/**
+ 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
import useTask from 'react-task-z';

// const [start, setStart] = useState(false); => It is recommended to use relay screen or sync function
// with basic
const task = useTask({
    // starting: start,
    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
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

License

MIT

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.1.2

11 months ago

1.0.0

1 year ago