LogoutButton.tsx 449 B

12345678910111213141516
  1. import { useMutation } from 'react-apollo'
  2. import { USER_LOGOUT, CURRENT_USER } from './graphql'
  3. interface LogoutButtonProps {
  4. title?: string
  5. }
  6. const LogoutButton = (props: LogoutButtonProps) => {
  7. const [logout, { loading, error }] = useMutation(USER_LOGOUT)
  8. return (
  9. <button disabled={loading} onClick={() => logout({ refetchQueries: [{ query: CURRENT_USER }] })}>{props.title || 'Log out'}</button>
  10. )
  11. }
  12. export default LogoutButton