The SUSPENSE is killing me...asyncReduxly - 401-advanced-javascript-aimurphy/seattle-javascript-401n13 GitHub Wiki
React SUSPENSE! Why? helps with async CPU power and data fetching You can render the dom tree when you want to, not pieces coming in whenever the arrive~ such as in the cases of: parent and child loading states, or waiting on a component to load only after the child has.
SUSpense works with createFetcher
on npm!
and this is how you do it:
- In the render() method, read a value from the cache
- If the value is already cached, the render continues like normal
- If the value is not already cached, the cache throws an error
- When the promise resolves, React continues from where it stopped
import { createResource } from 'simple-cache-provider';
const someFetcher = createResource(async () => {
const res = await fetch(`https://api.github.com/search/users?q=yomete`);
return await res.json();
});
export default someFetcher;