React v0.13 RC – Mutating this.props emits warning


React v0.13 RC was recently announced.

Let’s look at what changed in ‘this.props’

Mutating props after an element is created is deprecated and will cause warnings in development mode; future versions of React will incorporate performance optimizations assuming that props aren’t mutated

Starting from v0.13 RC, mutating this.props will emit a warning in development mode (and only in development mode). Development mode is the unmagnified ‘react.js’.

Nothing really happened when you wrote mutation code on ‘this.props’ in previous versions of react.js like below.

In v0.13 RC development mode, a warning will be emitted telling you not to mutate ‘this.props’.

Warning: Don't set of the React component <ExampleApplication />. Instead, specify the correct value when initially creating the element.

It just emits a warning but maybe in future release it might even throw an exception. Future releases of react.js will assume that you haven’t mutated ‘this.props’ and will optimize performances related to that condition.

Written on February 28, 2015