LogoutButton.tsx 633 B

12345678910111213141516171819202122232425
  1. import { useUserLogoutMutation, CurrentUserDocument } from '../../gql'
  2. interface LogoutButtonProps {
  3. title?: string
  4. }
  5. const LogoutButton = ({ title }: LogoutButtonProps) => {
  6. const [logout, { loading, error }] = useUserLogoutMutation(
  7. { refetchQueries: [{ query: CurrentUserDocument }] }
  8. )
  9. return (
  10. <button disabled={loading} onClick={async (event: React.SyntheticEvent) => {
  11. try {
  12. const data = await logout()
  13. console.log('LogoutButton', data)
  14. } catch (error) {
  15. console.log('LogoutButton', error)
  16. }
  17. }}>{title || 'Log out'}</button>
  18. )
  19. }
  20. export default LogoutButton