小编Ale*_*kiy的帖子

如何在 React 中使用 useState() 渲染组件之前使用 useNavigate()

我正在使用 React 和 apollo-client。如果用户不是注释的所有者,则应重定向该注释。但重定向后我收到:Warning: Cannot update a component ('BrowserRouter') while rendering a different component ('EditNote'). To locate the bad setState() call inside 'EditNote'。据我了解,组件中存在useState()问题<NoteForm/>。我做错了什么?

import React, { useEffect } from "react";
import { useMutation, useQuery } from "@apollo/client";
import { useNavigate, useParams } from "react-router-dom";

import NoteForm from "../components/NoteForm";

import { GET_NOTE, GET_ME } from "../gql/query";
import { EDIT_NOTE } from "../gql/mutation";

const EditNote = () => {
    const navigate = useNavigate();
    const params = …
Run Code Online (Sandbox Code Playgroud)

reactjs react-apollo apollo-client react-hooks

6
推荐指数
1
解决办法
1363
查看次数