How does lifting state up in a React application help with managing data flow and what are the benefits of using this approach?
https://legacy.reactjs.org/docs/lifting-state-up.html
Lifting state allows for two child components to be in sync with each other. In this way, the data is simultaneously transferred, which allows for a proper desired outcome. Rather than each being handled independently, and introducing the potential for a bunch of errors and synching issues, they are handled together in one parent state component, thus offering a single source of truth.
Explain the concept of conditional rendering in React and provide an example of how to implement it in a component.
Conditional rendering utilizes a flavor of if statements to conditionally render out some piece of code. What it does if the statement evaluates as False depends on the technique used.
The most flexible option is:
function Item({ name, isPacked }) {
let itemContent = name;
if (isPacked) {
itemContent = (
<del>
{name + " ✔"}
</del>
);
}
return (
<li className="item">
{itemContent}
</li>
);
}
But there is also the “&&” statement method. Note, nothing will render if the first part is False.
return (
<li className="item">
{name} {isPacked && '✔'}
</li>
);
The other options is using a ternary:
return (
<li className="item">
{isPacked ? name + ' ✔' : name}
</li>
);
What are the main principles behind “Thinking in React” and how do they guide the process of designing and building a React application?
More about two-way binding.