Stores & CreateResource

Why createResources doesn't work with a store? console.log("currentPageParam", params.currentPage) properly shows me that the store itself is being updated, but the signal change is not being passed into createResource like with a regular signal does. If instead i use a regular signal currentPage() the signal is triggered on createResource, what i am missing?
const pagination = createPagination();
const [params, setParams] = createStore<ConstructionCatalogItemListParams>();
const [currentPage, setCurrentPage] = createSignal<Record<string, string>>();
const [itemResource] = createResource(params, constructionCatalogItemList);

createEffect(() => {
// here i am updating my store query params values, these values are coming from pagination context.
setParams((prev: ConstructionCatalogItemListParams) => {
// setCurrentPage is a signal as my plan B, this shouldn't be here if stores worked
console.log("currentPage:", pagination.currentPage());
setCurrentPage({ currentPage: pagination.currentPage().toString() });
return {
...prev,
currentPage: pagination.currentPage(),
};
});
// params was successfully set.
console.log("currentPageParam", params.currentPage);
});
const pagination = createPagination();
const [params, setParams] = createStore<ConstructionCatalogItemListParams>();
const [currentPage, setCurrentPage] = createSignal<Record<string, string>>();
const [itemResource] = createResource(params, constructionCatalogItemList);

createEffect(() => {
// here i am updating my store query params values, these values are coming from pagination context.
setParams((prev: ConstructionCatalogItemListParams) => {
// setCurrentPage is a signal as my plan B, this shouldn't be here if stores worked
console.log("currentPage:", pagination.currentPage());
setCurrentPage({ currentPage: pagination.currentPage().toString() });
return {
...prev,
currentPage: pagination.currentPage(),
};
});
// params was successfully set.
console.log("currentPageParam", params.currentPage);
});
7 Replies
mrVinicius
mrViniciusOP3mo ago
My guess as to why the store version is not being triggered is that, since I'm not manually calling an item from the store, the reactive system isn't being set. With that said, is there a workaround for this, or should I just use a signal?
Alex Lohr
Alex Lohr3mo ago
direct mutation without produce is not working with set store functions. But if you want to store the data of your resource in a store, there is makeDeepSignal in the @solid-primitives/resource package.
mrVinicius
mrViniciusOP3mo ago
No description
Alex Lohr
Alex Lohr3mo ago
Sorry it's create not make My mistake
mrVinicius
mrViniciusOP3mo ago
Hmm, that seems to add way too much complexity into my problem, just gonna stick with regular signals for this use case.
REEEEE
REEEEE3mo ago
Possible simple solution is to just do
const [itemResource] = createResource(() => JSON.parse(JSON.stringify(params)), constructionCatalogItemList);
const [itemResource] = createResource(() => JSON.parse(JSON.stringify(params)), constructionCatalogItemList);
Alex Lohr
Alex Lohr3mo ago
Please use structuredClone() instead of abusing JSON.
Want results from more Discord servers?
Add your server