SolidJSS
SolidJSโ€ข3y agoโ€ข
17 replies
Nin

How to mutate a createResource storage

Hi all, I'd like to get some help with mutating a store that is set as a createResource storage.

function createDeepSignal<T>(value: T): Signal<T> {
  const [store, setStore] = createStore({
    value
  });
  return [
    () => store.value,
    (v: T) => {
      const unwrapped = unwrap(store.value);
      typeof v === "function" && (v = v(unwrapped));
      setStore("value", reconcile(v));
      return store.value;
    }
  ] as Signal<T>;
}

const [resource, {mutate, refetch}] = createResource(fetcher, {
  storage: createDeepSignal
});


Given the above snippet, I can access my store regularly by running resource() this returns the contents of my store, but how can I mutate it? Mutate only accepts one argument and usually setStore would receive multiple.
Was this page helpful?