Skip to content

Instantly share code, notes, and snippets.

@Kevnz
Created June 22, 2019 02:59
Show Gist options
  • Save Kevnz/c80be4e2ecefc0f45fccc7902008c3f8 to your computer and use it in GitHub Desktop.
Save Kevnz/c80be4e2ecefc0f45fccc7902008c3f8 to your computer and use it in GitHub Desktop.
UseAync
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