S
SolidJS12mo ago
skykanin

How to fetch chunks of data with createResouce?

How can I use createResource to fetch chunks of data from a paginated API endpoint? I need to fetch more data when the user clicks a button and then store that somewhere. Afaict you can't update the data createResource stores since refetching, mutating will get rid of the old data right? Do I need to store the data in a signal for this?
2 Replies
skykanin
skykanin12mo ago
https://playground.solidjs.com/anonymous/4ad69fb3-2580-427d-b435-860cbfe8cb53 ok so I totally missed that the fetcher is passed a value argument which corresponds to the old value of the createResource signal if it has one. Then we can use value in the fetcher to merge the old and new state.
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
skykanin
skykanin12mo ago
thanks would nesting suspenses be equivalent to the second optimization? I'm not sure when to use or not to use suspenses. I thought it was good practice to use them together with createResource right, and that would be wrapped in a suspense isn't the advantage of suspense over show that you can load dom elements while the data is being fetched instead of doing all the work when the promise resolves
Want results from more Discord servers?
Add your server