我希望能够始终使用 useEffect 来更改我的组的名称

I want to be able to use useEffect always that I change the name of my group

useEffect(() => {
  Axios.get(`https://taskcontrolapp.herokuapp.com/taskcontrol/grupo/${props.id}`)
    .then(response => {
      setGrupo(response.data)
    }).catch(error => {
      console.log(error)
    })
}, [])

我有一个对象 Grupo{ grupo_id 和 grupo_nome } 我想更改 grupo_nome 并再次使 useEffect 运行 ,已经尝试了许多变量作为参数和从来没有用过。

根据几篇文章和 React 文档,像这样把它放在 useEffect 中是不好的做法。

建议您将其包装在异步的 useCallback 中,或者将其包装在 useEffect 中的函数中,然后在 useEffect 中调用该函数。

在此处查看这些文章:

The Abramov guy

Official docs on custom hooks

useEffect(() => {
  async function someFunc () {
   await Axios.get(`https://taskcontrolapp.herokuapp.com/taskcontrol/grupo/${props.id}`)
    .then(response => {
      setGrupo(response.data)
    }).catch(error => {
      console.log(error)
    })
 }

someFunc()

 return () => {
   // do some clean up here 
 }

// Note the dependency array here...
}, [props.id, grupo_nome])