Conditional fetching with createResource
Hi!
Alright, this might be a little bit silly but here's my problem:
I have a context provider component that fetches some data to be used later, with createResource. But I'm passing a boolean to the context provider as props, and I'd like the data to be fetched only if the boolean is set to true. What would be the best way to handle this?
I'll provide some code if needed but really it's just a simple createResource calling the simplest fetcher.
Thank you in advance, have a nice day!
3 Replies
You can use the boolean as the resource source, and the data should only be fetched if it's true:
If the booleanValue is a signal, it'll automatically fetch if it's set to true
Wow, it works perfectly, thank you!
You're welcome :)