【发布时间】:2021-05-30 04:02:03
【问题描述】:
我有一个存储在状态中的数组。当我尝试将新数据推送到数组时,它返回此错误:
Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.
这是我正在使用的代码:
const [currencies,setCurrencies] = useState(['USD', 'AUD', 'SGD', 'PHP', 'EURP']);
setCurrencies(currencies => [...currencies, 'NSD', 'PLN']);
【问题讨论】:
-
能否提供完整代码?或者提及您在哪里调用 setCurrencies 函数?
-
这能回答你的问题吗? How to push setState array to data?
标签: react-native react-hooks use-state