Simple, native React solution for fetching & caching data using hooks. Based on react-hooks-example.
- < 1KB (not including axios, but that can be easily swapped with
fetch
or any promise library) - Caches requests: will only re-fire if a request parameter has changed
- Component can be re-rendered; request won’t fire unless necessary
npm install react@next react-dom@next axios
This also requires jest-mock-axios for Jest testing. Follow the instructions on that repo for setup instructions (not covered here).
Example usage: