0
0
Reactframework~5 mins

Sharing state between components in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean to share state between components in React?
It means making some data available to more than one component so they can all use or update it together, like sharing a common notebook between friends.
Click to reveal answer
beginner
How can you share state between a parent and its child component?
The parent holds the state and passes it down to the child using props. The child can also receive functions from the parent to update that state.
Click to reveal answer
intermediate
What is 'lifting state up' in React?
It means moving the shared state to the closest common parent of components that need it, so they can all access and update the same state.
Click to reveal answer
intermediate
Name a React hook commonly used to share state across many components without passing props deeply.
The useContext hook lets components access shared state from a context provider without passing props through every level.
Click to reveal answer
beginner
Why is it better to avoid duplicating state in multiple components?
Duplicating state can cause inconsistencies and bugs because changes in one place won’t update the others. Sharing state keeps data in sync everywhere.
Click to reveal answer
Which React feature helps share state without passing props through many components?
AuseRef hook
BuseEffect hook
CuseContext hook
DuseState hook
What does 'lifting state up' mean?
AMoving state to the closest common parent component
BPassing state down as props
CUsing local component state only
DDuplicating state in multiple components
If a parent component holds state and passes it to a child, how can the child update that state?
ABy using useEffect hook
BBy directly changing the parent's state variable
CBy creating its own state variable
DBy calling a function passed from the parent as a prop
Why should you avoid duplicating state in multiple components?
AIt reduces code complexity
BIt can cause inconsistent data and bugs
CIt makes the app faster
DIt helps components work independently
Which of these is NOT a way to share state between React components?
AUsing local variables inside each component
BUsing React Context with useContext hook
CUsing props to pass state from parent to child
DLifting state up to a common parent
Explain how you would share a piece of state between two sibling components in React.
Think about where the state should live so both siblings can access it.
You got /3 concepts.
    Describe the role of React Context and useContext hook in sharing state.
    Imagine a shared storage accessible by many components.
    You got /3 concepts.