S
SolidJS11mo ago
Mathieu

How to handle requests that need to be fetched later?

I use createResource to fetch data from the server and make it a reactive store. But on one page I have tabs. Say Users, Articles, Organizations tabs. For now, when a user navigates to this page, I send 3 requests to the server, and create 3 resources (create or get if already created previously).
const [users] = useUsersResource() // create the resource or return existing one
const [articles] = useArticlesResource()
const [organizations] = useOrganizationsResource()
const [users] = useUsersResource() // create the resource or return existing one
const [articles] = useArticlesResource()
const [organizations] = useOrganizationsResource()
But I would like to fetch e.g. the articles only when its tab Articles is clicked on. As (if I'm not wrong) I need the createResource call in the synchronous execution (and thus not in a callback), how could I achieve that? (note that my app is CSR only)
4 Replies
Martnart
Martnart11mo ago
2 straightforward approaches come to mind: 1. Make your tabs page a layout and have separate pages with their own routeData 2. Work with source signals to conditionally trigger resources https://playground.solidjs.com/anonymous/ad3fb56c-8b2b-4ea7-bff7-aec30ae305bd
Mathieu
Mathieu11mo ago
the fetcher is not executed when the source signal is false? I don't see that documented?
mdynnl
mdynnl11mo ago
yeah, it's barely visible https://docs.solidjs.com/references/api-reference/basic-reactivity/createResource#:~:text=In%20these%20snippets,its%20first%20argument. https://www.solidjs.com/docs/latest/api#createresource:~:text=In%20these%20snippets,in%20a%20function. not really sure how we could improve the docs, maybe a list of gotchas (lol i just remembered saying this like a year ago, i really need to find the time to contribute these days)
Mathieu
Mathieu11mo ago
ty!
Want results from more Discord servers?
Add your server
More Posts
Solid Start: CSR Only PageI have one page that is very interactive and if client side rendering is not available I'd like to dRemove element from store not workingI'm trying to remove an element from a reactive store based on the index. I've tried versions of thiProtected route dynamic route that has to match certain parameterI have a dynamic route for a user. The file route looks like this: routes/(home)/user/[user]/(user).Default values in props with Merge Giving me a weird interfaceIn the situation where I want to possibly pass in prop, say `arrOfStrings`: ``` tsx interface CompoSolidjs site metadata (title, description, meta image etc.) in JavascriptI'm having difficulty with setting up metadata. My site is purely client side. When I use `@solidjs/Panda CSS and Solid-Start = FOUCWhen using Panda CSS with Solid-Start, I notice there is some major FOUC happening regardless of howIs there something like a replacePathParameters method?Hello, I'm trying to do something like this with the SolidJS router: ```ts replacePathParameters("SolidStart with the static adapter and hynrid routing?Hello! Is the hybrid routing (islandsRouter) supposed to work with the static adapter in SolidStart?What should I use if I want features of both Resources and Stores?I'm using `createResource` in a `RouteDataFunc`, which fetches a JSON tree asynchrconously. I love unoUiSlider rerenders when moving sliderHello, I have an issue with noUiSlider(https://refreshless.com/nouislider/) i want to make a slider