Error when using "createResource" as global.
So, look at the image. On it you see that the Resource is global scoped. But i got the error "Cannot use 'in' operator to search for 'data' in undefined", it's a bug? How i can fix this "bug", because when i do many same resources, it's fetches all of them, and so big load on server...
I tried some things, like using the "createRoot", or "resource.latest", it's not working.
I don't know english so good, because i am living in country, with different language π.
7 Replies
createResource is intended to be declared inside the components because of some internal stuff the SSR manages (one of this is unique id generation, which is tied to the SSR's instance)
Oh, so i can't solve this problem by another way?
no sorry. The closest you'll get is a createResource at your root component
Okay, thanks you π
Or use createAsync inside any component you need and wrap resdata in the cache function of solid router which will dedupe requests, meaning there will only be one fetch call no matter how many components fetch resdata with createAsync.
See the solid start docs for data loading:
https://docs.solidjs.com/solid-start/building-your-application/data-loading#data-loading-always-on-the-server
Thanks you so much) it works! But why createAsync doesn't trigger Suspence, when i call "revalidate" method? How i can fix that?
Well createAsync and Suspense are actually made to work together like charmβ¦
Suspense will display the βpastβ while the new data is being fetched due to its unblocking nature.
Hereβs a codesandbox that shows that behaviour when you switch the tab:
https://codesandbox.io/embed/solid-suspense-tabs-vkgpj?file=/src/index.js&codemirror=1
Solid Suspense Tabs - CodeSandbox
Solid Suspense Tabs by ryansolid using babel-preset-solid, solid-js