【问题标题】:useState Array. ERROR Error: Too many re-renders. React limits the number of renders to prevent an infinite loop使用状态数组。 ERROR 错误:重新渲染过多。 React 限制渲染次数以防止无限循环
【发布时间】: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']);

【问题讨论】:

标签: react-native react-hooks use-state


【解决方案1】:

你能试试吗:

setCurrencies([...currencies, 'NSD', 'PLN']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-05
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2020-04-05
    • 2021-07-01
    • 2021-05-17
    相关资源
    最近更新 更多