Created
November 1, 2019 17:30
-
-
Save ilyamkin/6e0fb41f0733f6fc5e3b0cfa71cc86d0 to your computer and use it in GitHub Desktop.
Render with Suspense
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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