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).
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
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
the fetcher is not executed when the source signal is
false
? I don't see that documented?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)
ty!