Make a Resource depend on another Resource

I would like to have a resource depend (awaiting) on another, like so:
const [resource2] =
createResource(
async () => {
await resource1.promise; // no such property exists
return fetch();
});
const [resource2] =
createResource(
async () => {
await resource1.promise; // no such property exists
return fetch();
});
However I don't have access to the promise in the return of the resource: https://docs.solidjs.com/references/api-reference/basic-reactivity/createResource See ResourceReturn doesn't expose the promise/fetcher.
5 Replies
Mathieu
MathieuOP2y ago
This seems to work:
const [resource2] =
createResource(resource1, // pass the resource as the source signal
async () => {
return fetch();
});
const [resource2] =
createResource(resource1, // pass the resource as the source signal
async () => {
return fetch();
});
But not sure if it's the best way, for example: 1. what if we have multiple resources to wait for 2. I don't necessarily want to retrigger the fetcher when the source changes
mdynnl
mdynnl2y ago
you can check the state of source resources inside the fetcher
Mathieu
MathieuOP2y ago
Yes but I can't await for the state, right? So if I have an if-statement on the state, I might just skip the request at all
Mathieu
MathieuOP2y ago
Hey thank you for helping<3
Want results from more Discord servers?
Add your server