mst-query
mst-query copied to clipboard
v2
New helper functions that gives a you default run action: createQueryWithRun, createMutationWithRun.
export const ChatQuery = createQueryWithRun('ChatQuery', {
request: types.model({ id: types.string }),
pagination: types.model({ offset: types.number }),
data: MstQueryRef(ChatModel),
queryFn: api.getChat,
});
Infinite queries are easier with onQueryMore. After pagination changes, queryMore will be called with the new arguments. onQueryMore is used to determine how the new data should be appended.
const { data } = useQuery(ListQuery, {
request: { id: 'test' },
pagination: { offset: offsetProp },
onQueryMore(data, self) {
self.data?.items.push(...data.items);
},
});