You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using remix to build some "app-like" user interfaces. A common pattern is a tab bar across the top and then below that is a bunch of child routes. For each of these child routes I'm using defer so that the tab switches instantly and I show a loading spinner while the content is loading. This works well but is verbose to write.
Solution
One idea to making this easier would be a new hook - useAwaitedLoaderData(). This hook would basically work the same as useLoaderData() but is meant to work with defered data. It throws a suspense boundary until all the promises have settled and then you can use the data. This would mean you don't need to wrap you code in the loading + async components and instead can just use data like it has been awaited.
useAwaitedLoaderData would handle the types correctly. This assumes that there is a suspense boundary further up the stack. One idea could be to support a loading prop in an <Outlet /> to make this a little bit easier since that's often where you want to put the loading state.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
I've been using remix to build some "app-like" user interfaces. A common pattern is a tab bar across the top and then below that is a bunch of child routes. For each of these child routes I'm using
defer
so that the tab switches instantly and I show a loading spinner while the content is loading. This works well but is verbose to write.Solution
One idea to making this easier would be a new hook -
useAwaitedLoaderData()
. This hook would basically work the same asuseLoaderData()
but is meant to work with defered data. It throws a suspense boundary until all the promises have settled and then you can use the data. This would mean you don't need to wrap you code in the loading + async components and instead can just use data like it has been awaited.Here is an example of putting it together
useAwaitedLoaderData
would handle the types correctly. This assumes that there is a suspense boundary further up the stack. One idea could be to support aloading
prop in an<Outlet />
to make this a little bit easier since that's often where you want to put the loading state.Beta Was this translation helpful? Give feedback.
All reactions