Challenge: Build a World of Astronomy App with Context
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:
- Initialize the state for the input value using the
useStatehook. Set the initial value to an empty string (""). - In the
useEffecthook, 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 theuseEffecthook to ensure it runs when necessary. - Populate the
appDatavariable with the correct data. TheappDatavariable represents thecontextobject, and you need to includeinputValueandhandleInputChangefor theFiltercomponent.
In the Filter.jsx:
Get access to the inputValue and handleInputChange functions using the useContext hook.
- To initialize the state useΒ
useStateΒ hook. - For theΒ
useEffectΒ hook, includeΒinputValueΒ in the dependency array since the filtration depends on the user's input. - To set the data forΒ
appData, includeΒplanets,ΒinputValue, andΒhandleInputChange. - To accessΒ
inputValueΒ andΒhandleInputChange, use theΒContextΒ provided as the value for theΒuseContextΒ hook.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain how the filtering logic should work in the useEffect hook?
What should the handleInputChange function do exactly?
How do I connect the Filter component to the context?
Awesome!
Completion rate improved to 2.17
Challenge: Build a World of Astronomy App with Context
Swipe to show menu
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:
- Initialize the state for the input value using the
useStatehook. Set the initial value to an empty string (""). - In the
useEffecthook, 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 theuseEffecthook to ensure it runs when necessary. - Populate the
appDatavariable with the correct data. TheappDatavariable represents thecontextobject, and you need to includeinputValueandhandleInputChangefor theFiltercomponent.
In the Filter.jsx:
Get access to the inputValue and handleInputChange functions using the useContext hook.
- To initialize the state useΒ
useStateΒ hook. - For theΒ
useEffectΒ hook, includeΒinputValueΒ in the dependency array since the filtration depends on the user's input. - To set the data forΒ
appData, includeΒplanets,ΒinputValue, andΒhandleInputChange. - To accessΒ
inputValueΒ andΒhandleInputChange, use theΒContextΒ provided as the value for theΒuseContextΒ hook.
Thanks for your feedback!