Skip to content
Advertisement

React Hool re-render loop test Condition on state

I want to update and re-render for loop test condition on hook state update. After I update state hook the state is rerendered but I want to the loop to be rerendered too. I make a form. The length of the form depends on what number I enter on input.

Here is what I tried:

JavaScript

Advertisement

Answer

There is no need for the useEffect hook here, it’s not doing anything for you. You can render directly the JSX from the formLength state. eachForm also isn’t a valid React component, so it can’t be used like <eachForm />. The for-loop will also return during the first iteration and not return an array of div elements like I suspect you are expecting.

Example:

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