How can I make sure that data from createAsync is loaded, before passing it to another function
No matter what I do dirID is always undefined when it gets to other functions, createEffect also did nothing for me but that might be because I used it incorrectly.
7 Replies
To wait for
dirID
to load you'd need to have a Show
for dirID
, and put subDirs
etc inside that, so they're only created when dirID
exists.
Instead I'd do this so that fetching subDirs
etc doesn't have to be nested
That still didn't work, with code like this:
output of console logs is
Yeah it's always going to be undefined for a bit
If you really wanted to wait until it wasn't undefined, move
subDirs
and files
into the <Show when={dirID()}>
and use the callback form of Show
, that way youll have access to dirID
without it being undefinedOut of curiosity how is <Protected/> used?
Like is it user in app.tsx?
I'd favour resolving async dependencies on the async side; not the reactive side.
Can't you do:
As long as
dirId
evaluates to undefined, the fetch doesn't trigger. But once the first async resolves, it will?
At least that is how createResource
used to work. Is there a reason for this feature to be removed?You're thinking
createResource()
for the last two. createAsync()
doesn't have that signature.
To get a createAsync()
to refetch you revalidate()
the cache
(key) it consumes.
One advantage of the createAsync
/cache
split is that every component can have its own createAsync()
that share the same cache()
wrapper.
With createResource()
everybody shares the same accessor or each component with a createResource
will cause its own async op (e.g. fetch).
The latter is undesirable because
- multiple fetches
- separate components can be at different levels of staleness.GitHub
solid-router/src/data/createAsync.ts at 098a7947ae24f85d05bde76bf26...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router