⚛️ React Hook for Fetching Data & caching it in Localstorage
npm install usefetch-caching
Firstly, Import the package:
import { useFetch } from 'usefetch-caching';
Fetch an URL and store the response:
const response = useFetch(
`https://jsonplaceholder.typicode.com/todos`,
'todos'
);
Example use case:
function Todos() {
const response = useFetch(
`https://jsonplaceholder.typicode.com/todos`,
"todos"
);
return response != null ? (
response.map((todo, key) => (
<>
<h3>{todo.title}</h3>
<span>{todo.completed ? "✔️" : "❌"}</span>
</>
))
) : (
<>
<span>No todo's</span>
</>
);
}
export default Todos;
👤 Lars
- Github: @LJeremy
Give a ⭐️ if this project helped you!