Skip to content

Instantly share code, notes, and snippets.

@ilyamkin
Created November 1, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyamkin/6e0fb41f0733f6fc5e3b0cfa71cc86d0 to your computer and use it in GitHub Desktop.
Save ilyamkin/6e0fb41f0733f6fc5e3b0cfa71cc86d0 to your computer and use it in GitHub Desktop.
Render with Suspense
const IndexList = ({ prefetchedIndexes }) => {
const data = usePrefetchedQuery(prefetchedIndexes);
return data.majorIndexesList.map(index => (
<div key={index.ticker}>
Show {index.ticker}
</div>
));
};
const App = () => {
const [prefetchedIndexes, setPrefetchedIndexes] = useState();
return (
<>
<button
onClick={() => {
setPrefetchedIndexes(prefetchQuery(`${API}/majors-indexes`));
}}
>
Load all indexes
</button>
{prefetchedIndexes && (
<Suspense fallback={<span>Loading indexes list...</span>}>
<IndexList prefetchedIndexes={prefetchedIndexes} />
</Suspense>
)}
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment