Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: World of Astronomy App | React Hooks and Context
Mastering React

Challenge: World of Astronomy AppChallenge: World of Astronomy App

Task

In this task, you will continue working on the same app, adding a filtration feature that allows users to filter planets by name.

To create the filtration component, we need to create a form that maintains the state of the input value. Additionally, we require a function that will respond to changes in the input value.

Instructions

In the App.jsx:

  1. Initialize the state for the input value using the useState hook. Set the initial value to an empty string ("").
  2. In the useEffect hook, check the logic that will filter the data when the user changes the input field. Decide what should be included in the dependency array of the useEffect hook to ensure it runs when necessary.
  3. Populate the appData variable with the correct data. The appData variable represents the context object, and you need to include inputValue and handleInputChange for the Filter component.

In the Filter.jsx:

  1. Get access to the inputValue and handleInputChange functions using the useContext hook.
Hint
1. To initialize the state use useState hook.
2. For the useEffect hook, include inputValue in the dependency array since the filtration depends on the user's input.
3. To set the data for appData, include planets, inputValue, and handleInputChange.
4. To access inputValue and handleInputChange, use the Context provided as the value for the useContext hook.

Everything was clear?

Section 3. Chapter 12
course content

Course Content

Mastering React

Challenge: World of Astronomy AppChallenge: World of Astronomy App

Task

In this task, you will continue working on the same app, adding a filtration feature that allows users to filter planets by name.

To create the filtration component, we need to create a form that maintains the state of the input value. Additionally, we require a function that will respond to changes in the input value.

Instructions

In the App.jsx:

  1. Initialize the state for the input value using the useState hook. Set the initial value to an empty string ("").
  2. In the useEffect hook, check the logic that will filter the data when the user changes the input field. Decide what should be included in the dependency array of the useEffect hook to ensure it runs when necessary.
  3. Populate the appData variable with the correct data. The appData variable represents the context object, and you need to include inputValue and handleInputChange for the Filter component.

In the Filter.jsx:

  1. Get access to the inputValue and handleInputChange functions using the useContext hook.
Hint
1. To initialize the state use useState hook.
2. For the useEffect hook, include inputValue in the dependency array since the filtration depends on the user's input.
3. To set the data for appData, include planets, inputValue, and handleInputChange.
4. To access inputValue and handleInputChange, use the Context provided as the value for the useContext hook.

Everything was clear?

Section 3. Chapter 12
some-alt