Skip to content
Advertisement

How to create new components on every button click in “React”

So I want when the user clicks on the button, be able to create new CatagoryField Component that I made. When I place the component in a function and call it it will only create the component once. I will appreciate some help. I’m confused about how should I implement this?

App components

JavaScript

Advertisement

Answer

The best way in order to achieve the solution is to use a state with useMemo.and the problem with your code is that the creator acts as a function and it will only execute once try this.

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