react-async-watcher: React hook to execute and watch async function. This package is made for handle asynchronous tasks, such as backend API calls. Execute async function whenever and whatever you want. Provide execution status and result. Typescript support. super tiny
React hook to execute and watch async function
This package is made for handle asynchronous tasks, such as backend api calls.
import { useAsyncWatcher } from 'react-async-watcher';
const GetUsersButton = () => {
const { execute, reset, status, result, error } = useAsyncWatcher();
return (
<button
onClick={() => {
execute(async () => {
// fetch remote data
const data = await getUsersApi();
// you may want to post-process data, use redux dispatch and so on
// if return data, result variable will be filled with the data
return data;
})
}}
>
Get User List
</button>
);
}
Inside your React or React-Native project directory, run the following command:
yarn add react-async-watcher
or with npm
npm install react-async-watcher
const { execute, reset, status, result, error } = useAsyncWatcher();
You can pass type to useAsyncWatcher, eq: useAsyncWatcher(), then type of result will be number | undefined
execute(async () => {
// do whatever you want
// if your need to render some data
// return it, then result variable will hold the data
})
use it to clear status, result, error
"initial" | "loading" | "success" | "failure";
Author: xralphack Live Demo: View The Demo Download Link: Download The Source Code Official Website: https://github.com/xralphack/react-async-watcher License: MIT
Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.
Hire React JS developer from Technoduce, we have a team of experienced and expert Angular JS developer. With our hire React JS developer, you have complete control over the technical resource throughout the development process.
Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.
Bunch of VSCode Extensions that improve quality of your coding time no matter what stack you are using. In this post, you'll see Top VSCode Extensions for React, React Native, JavaScript and Productivity
Using the React cloneElement is a better way to build a component API props in ES6 Javascript and Typescript. Here's a tutorial on how to do so.