S
SolidJS14mo ago
hannus

how to trigger the fetcher in createResource if there are multiple signal values?

hello, newbie here. In the document, it could be create a Memo as a group of signals as following. What's changed could be trigger the fetcher? id() or name()? or both? thanks a lot import { createResource, createMemo } from "solid-js"; // the fetcher function changed to accept an object async function fetcherFunc(info: { id: number; name: string }) { const response = await fetch( https://jsonplaceholder.typicode.com/users/${info.id}/posts?name=${info.name} ); return await response.json(); } const [id, setId] = createSignal<number>(1); const [name, setName] = createSignal<string>(""); // the derived state made using createMemo const derivedState = createMemo(() => ({ id: id(), name: name() })); const [posts] = createResource(derivedState, fetcherFunc);
2 Replies
lxsmnsyc
lxsmnsyc14mo ago
it's both. Also you don't have to use createMemo here just do createResource(() => ({ id: id(), name: name() }), fetcherFunc)
hannus
hannusOP14mo ago
thank you , I am going to try it.
Want results from more Discord servers?
Add your server