solid router's Data API
I'm a little bit confused about createAsync with the load function
In the example of the GitHub repo, there's a cache fn to fetch data
Then we attached it to the load function of the Route
Then in the current route component, we have to again attach the fetch function to the create async
Then why can't we just attach to the create async only? Why are we attaching the function to both Route's load fn and create async? This kinda confused me
6 Replies
The
loadUser
step is for preloading the data. createAsync
is for actually reading the data.
loadUser
can run before the route renders, or if the user has the intent to visit it
To be honest you can skip the load
property if you wanted toThanks, got it
so createAsync will fetch data on the client side only? since it's a wrapper around create resource?
what about fetching data from the server side?
no, it runs on both ends, like createResource
what about fetching data from the server side?Always createResource, that's how Solid achieves streaming SSR
so we can just ignore the RouteLoadFunc?
i tried implement like this
then run the build
then i tried running this script with bun
but the user data does not include in the html result
retried with createAsync instead, the script did call the api, but the html return still does not have user data
- You're using
renderToString
, it's not capable of server-side data fetching. You have to use renderToStringAsync
or renderToStream
.
- Suspense
is also a requirement for the SSR to know when to waitthanks, got it working