Question

In React,
what is "lifting state up"?
what it has do with having a single "source of truth"?
why is that important?

#react

Answer

In React, sharing state between components is accomplished by moving it up to the closest common ancestor of the components that need it. This is called "lifting state up".

This allows to have a single "source of truth" for any data that changes in a React application.

Having a single "source of truth" is desirable because if any state "lives" in some component and that component alone can change it, the surface area for bugs is greatly reduced. (When something is wrong in the UI, we can use React Developer Tools to inspect the props and move up the tree until finding the component responsible for updating the state.) Additionally, any custom logic to reject or transform user input will be in just one place.

https://reactjs.org/docs/lifting-state-up.html

Learn

Author

xavi

Reviews
Last
next

Students 1