Last active
October 28, 2019 22:32
-
-
Save pomber/358bfcde662168e5a9728ca4fa1ac051 to your computer and use it in GitHub Desktop.
Maybe some day we'll have something like this
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
function App({ items }) { | |
const [itemId, setItemId] = useState(null) | |
const [startTransition, prepareTransition] = useTransition(newId => setItemId(newId), { | |
timeoutMs: 1000 | |
}) | |
return ( | |
<Suspense fallback='Loading...'> | |
{itemId === null ? ( | |
<ul> | |
{items.map(item => ( | |
<li | |
onMouseEnter={() => prepareTransition(item.id)} | |
onClick={() => startTransition(item.id)} | |
children={item.name} | |
/> | |
))} | |
</ul> | |
) : ( | |
<ItemPage id={itemId} /> | |
)} | |
</Suspense> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment