“Lifting the State Up” or “Lifting State Up”
React has a component-based architecture approach, where components can be children, parents, or even siblings (children of the same parent component). Data – or state – can be passed from parent to child, but what about from child to parent, or sibling to sibling? In that case, we need to lift the state up. Lifting the state up can be passed via props. If passing from sibling to sibling, it should only be lifted up to the nearest parent component and then down to the child needing the data.
const [count, setCount] = useState(0);
What’s actually happening here? useState returns the current state and a function that updates it. So in order to initialize both values in one line, we use array destructuring. There are other methods to assign values within an array, but they usually require more lines of code, and therefore we can consider array destructuring as “syntactic sugar”.
Rounding out this little list of developer jargon brings us full circle, back to comprehensible communication, and code is no exception! These days, there are languages and applications that make coding quite close to our common tongue. New languages and updates to existing frameworks often strive to develop syntax that is easy to comprehend, write, and read. Syntactic sugar is the phrase used for this sentiment.
The world of code is vast, there’s always something new to learn, the concepts can be tough to grasp and convey. If you find yourself frustrated by all of the terms, have patience. Just as coding can become second nature, with enough exposure, these terms start to feel more and more common. If you freelance or work as the only developer in your department and have few people to discuss your code with, I have found online video courses to be particularly helpful. While there are lots of resources to read from, I find having the audio element of a teacher who explains the terms out loud really helps me remember and lock in terms used when communicating developer-to-developer. Keep a beginner’s mind and stay curious!