Trigger useQueries fnc in onSuccess of other func, but queryOptions fnc has diff queryKey
export const useFetchDataScreen = (id:number):any => {
const assignDataFn = (id: number) => {
return queryOptions({
queryKey: ['assignKey',id],
queryFn: () => getAssign(id),
enabled:!!id
})
}
const getRoles = () => {
return queryOptions({
queryKey: ['getRoleUser],
queryFn: () => getRolesUser(),
enabled:!!roleId
})
}
return useQueries({
queries: [assignDataFn(id), getRoles() ],
combine:([{data:permissionOfRoles}, roles, allPermissions])=> {
//// logic and return data
},
})
};
this is first fn to render data
and this is the func i need to help:
export const useAssignRoleForPermission = (roleId:number) =>
return useMutation({
mutationFn: (payload:any) => postFn(payload),
mutationKey:['post_fn_key'],
onSuccess:() => {
// i need call useFetchDataScreen in here
}
})
}
2 Replies
fascinating-indigo•2y ago
That is not allowed as per rules of react
The question is what you really want to solve!
To simply answer your question: queryClient.fetchQuery is what you say you want, but probably not what you need
fair-rose•2y ago
You could define the hook like this, maybe?
Pretty standard pattern I believe.