Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
useMutation demo
const [execPostThread] = useMutation<any, any>(PostThreadMutation, {
refetchQueries: [
{
query: QueryMe
}
]
});
useEffect(() => {
if (askToPostThread && allowPostThread) {
setAskToPostThread(false);
execPostThread({
variables: {
threadId: localThread !== null ? localThread.id : "0",
userId: userProfile ? userProfile!.id : "0",
title,
body,
videoUrl,
bounty,
categoryId: selectedCategory!.id
}
})
.then(({ data }) => {
if (data.postThread && data.postThread.id > 0) {
const dataPostThread = data.postThread;
let message = "Thread posted successfully";
if (postBtnLabel === "Edit") {
message = "Thread edited successfully";
}
setValidationSuccessMsg(message);
setLocalThread(dataPostThread);
setTitle(dataPostThread.title);
setBody(dataPostThread.body);
setBounty(dataPostThread.bounty);
setPostBtnLabel("Edit");
if (window.location.href.includes("/postthread")) {
setThreadUrl("/thread/" + dataPostThread.id);
} else {
setThreadUrl("");
}
}
})
.catch(err => {
setSummaryValidationErrors([cleanGraphQlError(err.message)]);
});
}
}, [askToPostThread, allowPostThread]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment