SolidJSS
SolidJSโ€ข3y agoโ€ข
19 replies
oneiro

Confused about resource mutation with `createDeepSignal` and `produce`

Hey folks,

I am trying to create a resource which gets updated on a button click, by fetching content from a server.
However the user may change parts of the data they have already fetched. When refetching the data, we want to make sure that all user changes are not being overwritten.

To allow changing small parts of the data and still being reactive, I use createDeepSignal from solid-primitives.

My resource is initiated like this:

export const [projectsFromStore, { refetch: reloadProjects, mutate: mutateProjects }] = createResource(loadProjects, {
    storage: createDeepSignal,
})


Store here is a persisted file.

By default this file is empty until the user fetches projects from a remote server for the first time.

This fetch function can be used repeatedly and should alter its behaviour depending on if the user already has fetched projects or not as described above.

My fetch function looks like this: (continuation in comment)
Was this page helpful?