forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseSignOut.ts
More file actions
28 lines (25 loc) · 712 Bytes
/
useSignOut.ts
File metadata and controls
28 lines (25 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* SPDX-FileCopyrightText: 2014-present Kriasoft <hello@kriasoft.com> */
/* SPDX-License-Identifier: MIT */
import * as React from "react";
import { graphql, useMutation } from "react-relay";
import { useSignOutMutation } from "./__generated__/useSignOutMutation.graphql";
const signOutMutation = graphql`
mutation useSignOutMutation {
signOut
}
`;
export function useSignOut(): () => void {
const [commit] = useMutation<useSignOutMutation>(signOutMutation);
return React.useCallback(
function () {
commit({
variables: {},
onCompleted(_, errors) {
if (errors) throw errors[0];
window.location.reload();
},
});
},
[commit]
);
}