From the course: Learning React Native
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Creating a custom hook
From the course: Learning React Native
Creating a custom hook
- [Instructor] React hooks give us a way to isolate and separate presentation from functionality. In the last lesson, we created the colorForm, which will collect a new color from the user and then pass it to the app js component via the on new color property. At present, we are simply displaying an alert, letting us know that we have to add this color. So I'm going to get rid of the alert and I'm going to get rid of the defaultColors. We need to capture new colors from our users and then add them to this list of colors. So using the useState hook, we're going to create a state variable for colors. And we also get a function for changing that state variable, set colors. Don't forget to change the default colors to colors. And now when the app initially renders, we see an empty list of colors. Now on line nine, I'm going to create a new function for adding colors. All we have to do is send the color that we want to add…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Responding to touches2m 30s
-
(Locked)
Using a touchable highlight3m 23s
-
(Locked)
Extracting a custom component3m 16s
-
(Locked)
Importing a custom component2m 10s
-
(Locked)
Using a flat list2m 20s
-
(Locked)
Creating a form3m 27s
-
(Locked)
Collecting input4m 26s
-
(Locked)
Creating a custom hook3m 20s
-
(Locked)
-
-
-