Skip to content
Advertisement

React App – My alert window is showing up twice

I don’t understand why this is happening – I have an app that increments and decrements a counter when the buttons are pressed to display an increasing list of easter egg brands from a collection. When the counter reaches the max number of eggs in the collection I want a popup to appear saying “Limit has been reached”. The popup appears, but when I click okay, the same popup shows up again!

Is the React component being called twice somewhere?

If anyone has any ideas, this would be much appreciated.

App.js

JavaScript

Counter.js

JavaScript

Egglist.js

JavaScript

Thanks,

Robert

London, UK

Advertisement

Answer

Does your index.js have the tag strict mode? If that’s the case, remove it and try again.

JavaScript

Try with this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement