If the user changes then name to Bobby then the form is dirty and SAVE button is enabled. This class is more straight forward than the EditableContainer class. Once you submit the form, the state object should look like this: This is how you can make use of controlled form inputs, which manage events for each element and store values to the state object of the components. It is a different approach than the controlled components approach; thus, the uncontrolled components approach is not suitable because it keeps the source of truth within the DOM itself. Some of our partners may process your data as a part of their legitimate business interest without asking for consent. We have to set initial state value inside constructor function and set click event handler of the element upon which click, results in changing state. In this example, if you click the button, the input will be updated; however, the text in the paragraph will not. Sorted by: -1. How Intuit improves security, latency, and development velocity with a Site Maintenance - Friday, January 20, 2023 02:00 - 05:00 UTC (Thursday, Jan Were bringing advertisements for technology courses to Stack Overflow, How to change the href attribute for a hyperlink using jQuery. In the example above, we added a handleClick event handler to the onClick prop and state active to the button text, so whenever a button is clicked it runs the handleClick function and changes the active state from false to true or vice versa. It binds the value of the text input with the text prop and makes the input a controlled component. If I understand your questions correctly, you want to render a different element in case of an "onClick" event. Are you sure you want to hide this comment? How do I conditionally add attributes to React components? I find it helpful to use Set as a conceptual model instead. For example: App.js. Add an onClick prop to a button element. This way, a form using a