当我停止使用useEffect挂钩之外的handleClick函数处理点击后,出现以下错误:
错误:重新渲染次数过多。 React限制了渲染次数以防止无限循环。
是否无法像下面尝试的那样处理点击?
这些是我的有状态组件
const [value, setValue] = useState([])
const [isLoading, setLoading] = useState(false)
const [buttonValue, setButton] = useState(false)
这是我的useEffect Hook
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