how to await createResource?
This feel like such a silly question, but how do I await createResource. I am having all sorts of type errors because I can seem to get the flow control working and am hitting undefineds all over the place.
4 Replies
You don't await a createResource because that's the purpose of createResource: to convert a Promise into a signal.
It's natural for you to receive an undefined value because it is the placeholder value until the promise resolves, which then the resource updates with a new value. Things like createEffect would automatically rerun with this happens (if it happens that resource is being accessed in that context)
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
I understand that, I guess my question more directly is how do I effectivly handle undefined state in my typescript code so I can do computations with a createResource
specifically in the above data() is throwing a type error, as expected, I'm looking for a way to ensure that data() not undefined before I start using its values.
If it's direct to the UI, you can always do
If not: