State Management · Middle · Question 3 of 75
Why can storing a copy of a prop in state be a bug?
function Message({ color }) {
const [c, setC] = useState(color);
return <p style={{ color: c }}>Hi</p>;
}- ✓Correct answer: The initial value is used only once; later
colorchanges are ignored - 2
useStatecan't store strings received from props - 3React throws an error when state duplicates a prop
Explanation
"Mirroring" props in state freezes the first value. If the component should follow the prop, use it directly. Copy into state only when you intentionally need an initial value (and name it initialColor).