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
Tommypop
Tommypop13mo ago
You can use the boolean as the resource source, and the data should only be fetched if it's true:
const [data] = createResource(booleanValue, fetcher);
const [data] = createResource(booleanValue, fetcher);
If the booleanValue is a signal, it'll automatically fetch if it's set to true
Nyantastic
Nyantastic13mo ago
Wow, it works perfectly, thank you!
Tommypop
Tommypop13mo ago
You're welcome :)
Want results from more Discord servers?
Add your server
More Posts
Is there a polyfills.ts for `solid-start`? Or is there a way of modyfing the produced `index.html` ?So, in the `aws amplify` framework there is a common bug, which all frameworks have to fix somehow: Pure client based page complaining about `window is not defined` in solid-start (No SSR needed)Back when I was just working with `solid.js` I could use `window` in my code just fine, for. pages tWhy does typescript not accept `text() && text().length === x` in solid-start?Is anyone aware why typescript complains about ```ts text() && text().length === 6 ``` in a projecUniversal renderer createElement isn't runningI'm working on a custom renderer and I can't get the createElement function to run. I'm not sure if How to read reactive state from imperative contexts (audio/music)**tl;dr:** is there any major DO NOT guideline around (constantly!) reading reactive states from fuHow to handle auto scrolling in a chat app when new message comes in?So this is an example what i currently have ```jsx const App = () => { const [messages, setMessageHow to get `onMount` to be called on the client for a server-rendered siteI've set up a new project using `solid-start` with `solid-start-aws`. Running `npm run build` createReactivity with normal functionsI try the following: `doubleCount` is using `createMemo` while `tripleCount` is a normal anonymous fSolid-js design system CSS troubleshootingI have a design-system I am building out using Kobalte. However, when I export the components none oHow to throw an Error on an unknown route?I define the content for each route like so: ```jsx return ( <Routes> <Route path={'/foo'} ele