Skip to content

Instantly share code, notes, and snippets.

@dioxmio
Last active October 23, 2022 16:16
Show Gist options
  • Save dioxmio/32474493244b21f4d9753ebd88922d41 to your computer and use it in GitHub Desktop.
Save dioxmio/32474493244b21f4d9753ebd88922d41 to your computer and use it in GitHub Desktop.
// simulates a fetch
function fetchData() {
return new Promise((resolve) => {
setTimeout(() => {
resolve({foo: 'bar'});
}, 500)
});
}
// component wrapped with a parent <Suspense />
function Test() {
const data = use(fetchData());
// ✅ no need for a nullcheck of data
return (<div>Result is {data.foo}</div>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment