use-controllable-resolve
v0.2.0
Published
![](https://github.com/ZouYouShun/controllable-resolve/actions/workflows/main-merge.yml/badge.svg) ![](https://github.com/ZouYouShun/controllable-resolve/actions/workflows/npm-publish-use-controllable-resolve.yml/badge.svg) [![npm](https://img.shields.io/
Downloads
5
Maintainers
Readme
use-controllable-resolve
A hook to use controllable-resolve as a React hook to create a simple controllable promise resolve let you can control when to resolve promise
Demo
Installation
npm install use-controllable-resolve
Usage
useControllableResolve
import type { FC } from 'react';
import { useControllableResolve } from 'use-controllable-resolve';
export const UseControllableResolveExample: FC = () => {
const controllableResolve = useControllableResolve<number>();
const { waitResolved, resolve } = controllableResolve;
return (
<>
<button
onClick={() => {
waitResolved().then((value) => {
console.log('🚀 ~ value', value);
});
}}
>
Start
</button>
<button
onClick={() => {
resolve(100);
}}
>
Resolve
</button>
</>
);
};
API
For more detail api, view on controllable-resolve,
that use-controllable-resolve
just a wrapper with that, and provide you some hints about that.