React · Senior · Question 60 of 75
Why doesn't <ExpensiveTree /> re-render when ColorPicker state changes here?
function ColorPicker({ children }) {
const [color, setColor] = useState("red");
return <div style={{ color }}>{children}</div>;
}
// <ColorPicker><ExpensiveTree /></ColorPicker>- ✓Correct answer:
childrenwas created by the parent, so its element is the same object whenColorPickerre-renders - 2React never re-renders
children - 3
styleprevents re-renders
Explanation
Passing JSX as children ("lifting content up") is a memo-free optimization: only the parent that created the element decides when it changes.