Using useQueryClient inside onSuccess

Does anyone know if we can use the useQueryClient in the onSuccess function?
The main reason is I want to use helper functions from other files.

Card.query.ts
export const sendAddCard = () => {
    const queryClient = useQueryClient()
    return createMutation({
        mutationKey: [MutationKeys.Folders],
        mutationFn: (data: PostAddCardModel) => postAddCard(data),
        onSuccess: (cards, data, q,) => {
            // Use let cards = _getFolders() instead of:
            let folders = [...queryClient.getQueryData([QueryKeys.Folders])]

            // Also useQueryClient will give error if we use it in onSuccess function
        },
    })
};



Folder.helper.ts
export function _getFolders() {
    const queryClient = useQueryClient()
    return queryClient.getQueryData([QueryKeys.Folders])
}
Was this page helpful?