DEV Community

David Miller
David Miller

Posted on

React Help

Here's a link codesandbox project I'm working on. Can anyone tell me why the button at the bottom of form component stops resetting the Rate component once I put it inside the ternerary operator, please?

Top comments (1)

Collapse
 
lucasm4sco profile image
Lucas • Edited

Hello David, I hope you are well!

Taking a look at your code, it seems to me that the default behavior of the button reset is not occurring, I believe it is due to its rendering conditionally, because as soon as the state variable changes in the Reset function, the component is disassembled and therefore the button loses its function in DOM.

If you still want to do conditional rendering in your code, take a look at using state variables for the select component or if you prefer, you can use a reference to the form to execute the reset event, I found a post with an example of how to use the select in React: Creating forms in React

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay