DeleteUserButton.tsx 528 B

123456789101112131415161718192021
  1. import { useMutation } from "@apollo/react-hooks"
  2. import { USER_DELETE } from './graphql'
  3. import { SyntheticEvent } from "react"
  4. interface DeleteUserProps {
  5. user: {
  6. id: string
  7. }
  8. title?: string
  9. }
  10. const DeleteUserButton = ({ title, user: { id } }: DeleteUserProps) => {
  11. const [deleteUser, { loading, error }] = useMutation(USER_DELETE)
  12. return (
  13. <button onClick={(event: SyntheticEvent) => {
  14. deleteUser({ variables: { id } })
  15. }}>{title || 'Delete user'}</button>
  16. )
  17. }
  18. export default DeleteUserButton