简体   繁体   中英

Nextjs graphql mutation stuck send request

This is my code to delete a user:

  const [selected, setSelected] = useState<string | null>(null);


  const DELETE_USER = gql`
    mutation RemoveUser($_id: String!) {
      removeUser(_id: $_id)
    }
  `;
  const [removeUser, { loading, error }] = useMutation(DELETE_USER);

  const handleDelete = () => {
    removeUser({
      variables: {
        _id: selected,
      },
    });
  };


...

 <Button isLoading={loading} onClick={handleDelete} variant="ghost">
              Delete
            </Button>

Note : selected is always non empty before the handleDelete function call.

I don't get any error or warning and I am just stuck in the loading state in the UI.

env variable was undefined on the client-side in nextjs. the problem is solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM