Async Primitive
Hi I'm a bit stuck, you know that primitive is asynchronous and can be used in a following case.
there's the createResource primitive, but I can't see how to use it properly, especially as I'd like to be able to put the files in indexedDB.
5 Replies
Yes,
createResource
is definitely the answer! You give it an async function and it returns a signal with additional properties about the fetch call (it's pending state, if it errored, ...). It's a very powerful primitive, especially how it works together with suspense
. Is there something specific about createResource
that you have troubles with?the getImage is async, and can restart a refetch or fetch in indexedDB, which seems to me to make the software more complex.
Something like this should be fine regarding
createResource
. if you want 'key_image' to be dynamic you could change it into a signal:
or if it comes from a prop:
thank you very much, I can see the idea.
ur welcome!