Created
June 22, 2019 02:59
-
-
Save Kevnz/c80be4e2ecefc0f45fccc7902008c3f8 to your computer and use it in GitHub Desktop.
UseAync
This file contains hidden or 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
import React, { useEffect } from 'react' | |
import { useAsync } from '@brightleaf/react-hooks' | |
export default () => { | |
const { loading, error, data, execute } = useAsync(asyncFunction) | |
useEffect(() => { | |
execute() | |
}, []) | |
if (loading) { | |
return <div>Executing Async Function</div> | |
} | |
if (error) { | |
return <div>Error executing async function</div> | |
} | |
return <div>{data}</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment