S
SolidJS12mo ago
Mathieu

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
Mathieu12mo 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
mdynnl12mo ago
you can check the state of source resources inside the fetcher
Mathieu
Mathieu12mo 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
Mathieu12mo ago
Hey thank you for helping<3
Want results from more Discord servers?
Add your server
More Posts
vanilla js in onMount?I got help recently about finding a way to import a vanilla javascript file as an independent sourceEmpty event with useRequest()I'm getting an empty event (no properties on the object) via `useServerContext()` even when `isServeExample of using createWebSocketServer within an API endpoint with SSR: falseIs there a simple example of using createWebSocketServer within an API enpoint? Current `with-websocSolid Bootstrap Data TableHi Im looking for a custom solid-js data table solution. To minimize my workload, of course I beliHow to get `useParams` in the "root.tsx" in a server-rendered-page.Inside the `root.tsx` before any `FileRoutes` are resolved, how can we get the full path / the param[Solid-start]FileRoutes] is there a way of using two separate Routes folders in `root.tsx`E.g., my main content should be Client-Side rendered, but the headers should be server side renderedHow to call for server-side-data in the `root.tsx` of solid-start`Since I want to wrap my entire site in `<ClientOnly>` in the `root.tsx`, I can't use `useRouteData` Any tools for SolidJS that you wish you had?Hey everybody, My team and I working on an open source project with some restrictions; one of them bRouter Error when on a server with lazy loaded component on root pageWhen I deploy my website on a webserver and I load the "/" route I get an error in the browser consoRuntime Env vars in viteHey all, I'm trying to figure out a way to run environment variables *at runtime* rather than at com