SolidJSS
SolidJSโ€ข3y agoโ€ข
2 replies
deepvora92

Unable to mutate data created by createResource.

I have the following code that i'm trying to get to work but it doesnt update the node/ui

  const [tb, { mutate }] = createResource(
    () => [params.entityId, toDate()] as const,
    ([entityId, toDate]) => tbFetch(entityId, toDate),
  );
// usage
  <TreeView data={tb()!} mutate={mutate} />

<button
              class={twclsx('ml-2')}
              onClick={async () => {
                const searchParams = new URLSearchParams({});
                const tree = await apiPromise(
                  apiFetch(
                    `/entities/${params.entityId}/reports/master_balances/${props.item.id}?${searchParams.toString()}`,
                    {
                      credentials: 'include',
                    },
                  ),
                  'Failed to fetch trial balance',
                );

                if (props.mutate) {
                  props.mutate!(() => {
                    props.item.children = flattenTree(tree);
                    return props.data;
                  });
                }
              }}
            >
              {props.item.name}
            </button>
Was this page helpful?