Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:重新渲染过多。React限制渲染的数量以防止无限循环_Javascript_Reactjs - Fatal编程技术网

Javascript 错误:重新渲染过多。React限制渲染的数量以防止无限循环

Javascript 错误:重新渲染过多。React限制渲染的数量以防止无限循环,javascript,reactjs,Javascript,Reactjs,在我停止使用useEffect挂钩之外的handleClick函数处理我的点击后,我得到以下错误: 错误:重新渲染过多。React限制渲染的数量以防止无限循环 不可能像我在下面试过的那样处理舔吗 这些是我的有状态组件 const [value, setValue] = useState([]) const [isLoading, setLoading] = useState(false) const [buttonValue, setButton] = useState(false)

在我停止使用useEffect挂钩之外的handleClick函数处理我的点击后,我得到以下错误:

错误:重新渲染过多。React限制渲染的数量以防止无限循环

不可能像我在下面试过的那样处理舔吗

这些是我的有状态组件

  const [value, setValue] = useState([])
  const [isLoading, setLoading] = useState(false)
  const [buttonValue, setButton] = useState(false)
这是我的Useffect钩子

  useEffect(() => {
    axios.get('http://localhost:5000/').then(res => setValue(res.data))

    if (buttonValue === 'delete') {
      setLoading(true)
      axios.delete('http://localhost:5000/delete').then(() => {
        setLoading(false)
        setButton(null)
      })
    } else if (buttonValue === 'create') {
      setLoading(true)
      axios.post('http://localhost:5000/').then(() => {
        setLoading(false)
        setButton(null)
      })
    }
  }, [isLoading])

这些是我的纽扣

     <Form.Group>
        <Button variant='success' className='button' onClick={setButton('create')} id='create'>Create Sales Order</Button>
      </Form.Group>
      <Form.Group>
        <Button variant='danger' className='button' onClick={setButton('delete')} id='delete'>Delete Sales Order</Button>
      </Form.Group>
    </Form

创建销售订单
删除销售订单

onClick={setButton('delete')}
onClick={()=>setButton('delete')}
现在错误消失了,但当我按下按钮时什么也没有发生,然后尝试
onClick={(e)=>{e.preventDefault();setButton('delete');}}
谢谢你的回答,但这在
useffect
你引用的最后一行中也不起作用
[isLoading]
这意味着只有当
isLoading
更改时效果才会运行,您可能需要将其更改为
[按钮值]