
True or false? When lifting state up, you need to move the useState from a child component to a parent component.
True.
False.
If the state variable holds an array or a string value, once you pass that state via props from a parent to a child, you can then read the length property from the received prop in the child component.
True
False
What's wrong with this code?
import React from "react"; import Fruits from "./Fruits"; import FruitsCounter from "./FruitsCounter"; function App() { const [fruits] = useState([ {fruitName: 'apple', id: 1}, {fruitName: 'apple', id: 2}, {fruitName: 'plum', id: 3}, ]); return ( <div className="App"> <h1>Where should the state go?</h1> <Fruits fruits={fruits} /> <FruitsCounter fruits={fruits} /> </div> ); } export default App;If you don't add the
setFruitsstate-updating function when descructuring values fromuseState, the app won't compile.There's nothing wrong with the provided code.
The useState call should be
React.useState.
About the author
A passionate full-stack developer from @ePlus.DEV
Comments
Join the discussionNo comments yet. Be the first to comment.
React Basics
In this module you will explore the basic structure and use of the React.js library. You will learn how to produce single page web applications using React components and to use JSX to style them.






