Complete the code to lift the state up by passing the state value as a prop.
function Parent() {
const [count, setCount] = React.useState(0);
return <Child count=[1] />;
}The parent component passes the current state value count as a prop to the child.
Complete the code to lift the state up by passing the setter function as a prop.
function Parent() {
const [count, setCount] = React.useState(0);
return <Child onIncrement=[1] />;
}The parent passes the setter function setCount so the child can update the state.
Fix the error in the child component to call the passed setter function correctly.
function Child({ onIncrement }) {
return <Button title="Add" onPress=[1] />;
}The onPress expects a function. Wrapping onIncrement() in an arrow function ensures it is called only when pressed.
Fill both blanks to lift state up and handle input change in the parent.
function Parent() {
const [text, setText] = React.useState('');
return <Child value=[1] onChangeText=[2] />;
}The parent passes the current text state and a function to update it when the child input changes.
Fill all three blanks to lift state up and display the updated count in the parent.
function Parent() {
const [count, setCount] = React.useState(0);
return (
<>
<Child count=[1] onIncrement=[2] />
<Text>Count: [3]</Text>
</>
);
}The parent passes the current count, the setter function, and displays the count as text.