0.2.0 • Published 5 years ago

react-use-promise-hook v0.2.0

Weekly downloads
18
License
-
Repository
github
Last release
5 years ago

usePromise

To install run

npm i react-use-promise-hook

or

yarn add react-use-promise-hook

Usage

const counterPromise = () => {
	return new Promise(res => {
		setTimeout(() => res(Math.random()), 1000);
	});
};

const Example = () => {
	const [counter, errorMsg, loading, reset] = usePromise(counterPromise);
	if (loading) {
		return 'Loading...';
	} else if (errorMsg){
		return errorMsg;
	} else {
		return (
			<>
				<p>{counter}</p>
				<button onClick={reset}>Reset counter</button>
			</>
		);
	}
};
0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago