is there any way to get submitted data into onSuccess method when i am using useSWRMutation hook.
this is my submit function
const handleCreateQna = (
event: FormSubmitEvent,
{ parentId, msgId }: CreateQnaParamsType
) => {
const values = msgValues[msgId];
event.preventDefault();
setCreatedQnaId(msgId);
createQnaTrigger({
comments: values.comments,
userId,
courseId,
parentId,
assetUrl: [],
});
};
i want to get parentId in the onSuccess method to reset a value of state
const {
error: createQnaError,
data: createdQnaData,
trigger: createQnaTrigger,
isMutating: createQnMutating,
} = useSWRMutation('/api/user', fetcher, {
onSuccess: (response, ) => {
// set default value of the submited parentId
setMsgValues((pre) => ({
...pre,
[parentId]: qnaInitialValue,
}));
// revalidate the Q&A list
mutate(Api.getQnaByCourseId(courseId));
},
});