SolidJSS
SolidJS13mo ago
8 replies
sean

How to use query.set (prev cache.set) to mutate async data for optimistic updates?

i’m trying to use the undocumented query.set to mutate async data for optimistic updates.

it works for async data from createAsync that’s reactive to param change. however, when i manually revalidate the data (either by calling revalidate somewhere, or revalidating from an action), it fetches fresh data rather than using the query.set i called earlier

when should i use query.set if i’m going use revalidate() in order get the data? calling revalidate is the only way to get the data as my query isn’t reactive to a param change

i’m trying to do following

const data = createAsync(() => getData)
const createAction = action(async () => {
    const newData = createData()
    query.set(createData.key, newData)
    return reload({ revalidate: createData.key })
})

const create = useAction(createAction)

await create()


i’m expecting that it doesn’t create a new request, but rather use the data i set using query.set

i’m using query.set to avoid fetching getData() again because i already got the same data when i called createData()

is my usage correct? how do i properly use it to attain the behavior i described?

(sorry for bad formatting, typing on a phone)

thank you so much!!!
Was this page helpful?