Skip to content
Advertisement

Counter inside an onClick function

I have a button that adds a new div (onClick). I want to add +1 to cargoNumberCounter so that it shows that it’s a new div.

JavaScript

I thought I could make it work like I have shown in the example, or by spreading the state like so setCargoNumberCounter([...cargoNumberCounter, cargoNumberCounter +1]), but for some reason it doesn’t work.

Any thoughts on how to add +1 to each new div ?

Advertisement

Answer

It sounds like you may be better off with one button to add new items of cargo to the list. Here’s a quick example.

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