Created
July 4, 2019 18:49
-
-
Save icarus-sullivan/474c492d95b1e4297ea2444aada798eb to your computer and use it in GitHub Desktop.
Dynamic params for useAsync
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, { useState } from 'react'; | |
import { useAsync } from '@sullivan/use-async'; | |
const Example = (props) => { | |
const [url, setUrl] = useState('https://www.npmjs.com/package/@sullivan/use-async'); | |
const { loading, data, error, dispatch } = useAsync(fetch, url); | |
return ( | |
<div> | |
<div>Libraries</div> | |
<select value={url} onChange={(e) => setUrl(e.target.value)}> | |
<option value="https://www.npmjs.com/package/@sullivan/use-async">useAsync</option> | |
<option value="https://www.npmjs.com/package/react-spinner-material">Spinner</option> | |
<option value="https://www.npmjs.com/package/serverless-plugin-flambe">Flambe</option> | |
</select> | |
<button onClick={dispatch}>Request Page</button> | |
<pre>{JSON.stringify({ loading, data, error })}</pre> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment