Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,30 @@ | ||
import * as React from 'react'; | ||
import { useAsync } from '../..'; | ||
|
||
export const Example: React.FC = () => null; | ||
export const Example: React.FC = () => { | ||
const [state, actions] = useAsync( | ||
() => | ||
new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve('react-hookz is awesome!'); | ||
}, 3000); | ||
}), | ||
[] | ||
); | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<em>Async function will resolve after 3 seconds of wait</em> | ||
</div> | ||
<br /> | ||
<div>promise status: {state.status}</div> | ||
<div>current value: {state.result ?? 'undefined'}</div> | ||
<br /> | ||
<div> | ||
<button onClick={actions.reset}>reset</button>{' '} | ||
<button onClick={actions.execute}>execute</button> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters