max
max
SSolidJS
Created by max on 3/19/2024 in #support
Mutate data for optimistic updates with createAsync
Thanks!
14 replies
SSolidJS
Created by max on 3/19/2024 in #support
Mutate data for optimistic updates with createAsync
Thanks, I was reading through some github discussions and saw that there is a cache.set() method, do I just call this with the key value pair for the cache I want to update? Do I then need to call revalidate()? Also, just reading through the Cache Architecture on Github and it says: "cache API can be used with createResource but it must be passed into the tracking argument not the fetcher which means that you can't only pass a single argument as createResource defaults to just the fetcher. So to use a cache function with createResource you would need to:
const getUser = cache((id) => {
return (await fetch(`/api/users${id}`)).json()
}, "users") // used as cache key + serialized arguments

const [user] = createResource(
() => getUser(params.id),
v => v // pass the return promise through
);
const getUser = cache((id) => {
return (await fetch(`/api/users${id}`)).json()
}, "users") // used as cache key + serialized arguments

const [user] = createResource(
() => getUser(params.id),
v => v // pass the return promise through
);
" Is that all that needs to be done to use cache with createResource?
14 replies