From the course: React Hooks
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Managing form inputs with useRef - React.js Tutorial
From the course: React Hooks
Managing form inputs with useRef
- [Instructor] As we move our way through all of these different hooks that the React library provides us with, one that we can't overlook is useRef. So useRef is going to allow us to reach out to a component and determine its value. And this can be extremely useful, particularly with forms. So the first thing I want to do with our form is I want to import useRef. I'll get rid of all of our reducer stuff from before. Then inside of the component, instead of returning this here, we're going to say form and we'll close the form. Inside the form, I want to add an input with a type of text and then we'll add another one of these with a type color. Then I need to get rid of useReducer because we're getting those errors. Let's just make sure that this is rendering okay. Yeah, so we have our little input fields and then we have a little color picker. Let's also create a button, and the button should have text that says add. So this…
Contents
-
-
-
-
-
-
(Locked)
Handling complex state with useReducer2m 20s
-
(Locked)
Refactoring useState to useReducer1m 39s
-
Dispatching actions with useReducer4m 33s
-
(Locked)
Managing form inputs with useRef4m 58s
-
(Locked)
Creating controlled components with useState2m 50s
-
(Locked)
Solution: Building a counter3m 23s
-
(Locked)
-
-
-