createStore doesn't trigger createResource refetch action.

const [pagination, setPagination] = createStore({page: 1, limit: 10});
const [perPage, setPerPage] = createSignal(10);
const [constructionData] = createResource(perPage, getConstructionList); // works
//const [constructionData] = createResource(pagination, getConstructionList); // does not work
//const [constructionData] = createResource({page: pagination.page, limit: pagination.limit}, getConstructionList); // tried to deconstruct signal, did not work too
const [pagination, setPagination] = createStore({page: 1, limit: 10});
const [perPage, setPerPage] = createSignal(10);
const [constructionData] = createResource(perPage, getConstructionList); // works
//const [constructionData] = createResource(pagination, getConstructionList); // does not work
//const [constructionData] = createResource({page: pagination.page, limit: pagination.limit}, getConstructionList); // tried to deconstruct signal, did not work too
How can I make createResource work with a store, if possible at all? When I pass a simple signal like perPage to createResource, it works smoothly. However, when I pass a whole store to it, it does not trigger the refetch.
4 Replies
Alex Lohr
Alex Lohr3mo ago
That's because only the leaves of the store tree are reactive, the branches are not.
mrVinicius
mrVinicius3mo ago
Thought so, just wasn't sure. Gonna use regular signals for this then.
const [pagination, setPagination] = createSignal({page: 2, limit: 10});
const [pagination, setPagination] = createSignal({page: 2, limit: 10});
It's working nicely.
Madaxen86
Madaxen863mo ago
Or you can use the useSearchParams hook which provides a setter and getter so you can also refresh/reload the page and still have the previous page and limit. https://docs.solidjs.com/solid-router/reference/primitives/use-search-params#usesearchparams
mrVinicius
mrVinicius2mo ago
Oh thanks, i'll refactor try this out.
Want results from more Discord servers?
Add your server