Bernhard Gschwantner
1 min readNov 8, 2015

--

Great Article! I have one remark regarding purity: If you use contextType, the component is not stateless and pure — state can be modified through context. The same is true (but less likely) with the defaultProps: the function result could possibly be different if you change the defaultProps. If you use argument defaults, on the other hand, the function stays pure:

const Text = ({ children = 'Hello World!' }) =>
<p>{children}</p>

propTypes however don’t affect the purity of the function (if you leave the warnings in development out of the equation, but strictly speaking also those are side effects).

So my suggestion would be: If you want to use context, use ES6 classes or createClass. Instead of defaultProps, use argument defaults. That way, the intent is more obvious to other developers: functions only for pure components, classes for stateful components.

--

--