Add useFetch snippet

This commit is contained in:
Angelos Chalaris
2019-08-21 14:23:57 +03:00
parent da8096a895
commit bdd03cedfe
4 changed files with 147 additions and 0 deletions

View File

@ -463,6 +463,23 @@
"hash": "e8f3e64cd0cf616dd42843328234e37b1b7a77ed51da8956204fdb02e088ce33"
}
},
{
"id": "useFetch",
"type": "snippetListing",
"title": "useFetch",
"attributes": {
"text": "A hook that implements `fetch` in a declarative manner.\n\n- Create a custom hook that takes a `url` and `options`.\n- Use the `React.useState()` hook to initialize the `response` and `error` state variables.\n- Use the `React.useEffect()` hook to anychronously call `fetch()` and update the state varaibles accordingly.\n- Return an object containting the `response` and `error` state variables.\n\n",
"tags": [
"hooks",
"effect",
"state",
"intermediate"
]
},
"meta": {
"hash": "848cb6ba4f8bd5dad012a38e6bd0e7c829a79b3215a23939c30a3f652627da4f"
}
},
{
"id": "useInterval",
"type": "snippetListing",