S
SolidJS2mo ago
gsoutz

createResource signal isn't trigger if undefined or null

let fetcher: Signal<number | undefined> = createSignal(3)

let r = createResource(fetcher, async (v) => console.log(v))

fetcher[1](undefined) // doesn't log anything
fetcher[1](null) // doesn't log anything
let fetcher: Signal<number | undefined> = createSignal(3)

let r = createResource(fetcher, async (v) => console.log(v))

fetcher[1](undefined) // doesn't log anything
fetcher[1](null) // doesn't log anything
Sometimes I want resource to return undefined, when the underlying signal goes undefined. That's how I like it. Why is this forbidden?.. If I change undefined with true it triggers as I expect it. but undefined makes more sense here.
2 Replies
Brendonovich
Brendonovich2mo ago
that's just how createResource works, i think it's done so that you can return non-nullable values from fetcher and have them end up in the resource function, as opposed to just using a boolean
foolswisdom
foolswisdom2mo ago
Also in the docs https://docs.solidjs.com/reference/basic-reactivity/create-resource
fetchData will be called as soon as source has any value other than false, null, or undefined.
Feels like it could be better surfaced if also described not as part of a snippet
Want results from more Discord servers?
Add your server