I am having an array stored in a state. When I try to push new data to array, it is returning this error: Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.
This is the code I am using:
const [currencies,setCurrencies] = useState(['USD', 'AUD', 'SGD', 'PHP', 'EURP']);
setCurrencies(currencies => [...currencies, 'NSD', 'PLN']);
Can you try doing:
setCurrencies([...currencies, 'NSD', 'PLN']);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments