Skip to content

Latest commit

 

History

History

01-state

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Step 1 - State

Before hooks, a function component had to be converted to a class component if it needed to maintain state (or leverage lifecycle methods). A React Hook is a special function that lets you "hook into" React features. The useState hook lets you now add React state to function components.

🏅 The goal of this step is to switch from maintaining state with classes (using this.state & setState) to using the useState hook.

⭐ Concepts

  • Defining function components
  • Maintaining UI state with the useState hook
  • Rules of hooks

💡 Exercises

In App.js, convert the App class component into a function component using the useState hook to maintain the state of the input field.

(If at any point you get stuck, you can take a peek at the answers)

🧠 Elaboration & Feedback

After you're done with the exercise and before jumping to the bonuses, please fill out the elaboration & feedback form. It will help seal in what you've learned.

🤓 Bonus!

1. Display the query

Add a <p> below the <form> that will display "You are searching for [query] on Giphy." (with the query in bold). The message should only display when the query is non-empty.

2. Capitalize the message

Add a button that when clicked will toggle the query message between being upper-case and normal case.

🔑 HINT: You will need to add a second useState

📕 Resources

👉🏾 Next Step

Go to Step 2 - Effects.