When do we need to lift state in React?

Hello, can someone explain when and why do we need to lift state in React please. Like what should come to our mind for it to be spontaneous, "to achieve this", we must lift state "because lifting state allows us to...", I need the fill in my mental model gap :c
2 Replies
Ganesh
Ganesh3w ago
The most common case is when you need to share the same state between different components Remember that state only flows from parent to child component one way So if you have for example have a state in one component but you realise you also need it in another component you lift the state to a parent component that houses both components that need the state and pass the state as props
Faker
FakerOP3w ago
yep I see, thanks !

Did you find this page helpful?