Why can’t I update props in react.js?

The React philosophy is that props should be immutable and top-down. This means that a parent can send whatever prop values it likes to a child, but the child cannot modify its own props. What you do is react to the incoming props and then, if you want to, modify your child’s state based on incoming props.

So you don’t ever update your own props, or a parent’s props. Ever. You only ever update your own state, and react to prop values you are given by parent.

If you want to have an action occur on a child which modifies something on the state, then what you do is pass a callback to the child which it can execute upon the given action. This callback can then modify the parent’s state, which in turns can then send different props to the child on re-render.

Leave a Comment