From the course: React for Web Designers

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Forms in React: Controlled or not

Forms in React: Controlled or not - React.js Tutorial

From the course: React for Web Designers

Forms in React: Controlled or not

- [Instructor] The next step we'll be taking is updating our little app's state based on what happens in our filter form here. But before we do that let's take a brief pause to talk about the two main ways that you can work with forms in React. Specifically, we're going to be talking about controlled versus uncontrolled form elements. What we're asking here is who is the source of truth for the form data? It can either be React state or it can be the DOM elements that comprise the form. First, we'll talk about controlled components. A controlled form component is one where React is the source of truth or more specifically, React's state is the source of truth. That means that your code controls whether the form value changes. So, for example, you can do validation in your React code and then not update the state of the element that you're validating and the value won't change no matter what the user has typed. When you're working with controlled components every piece of state works…

Contents