pure()
can be used as a higher order function or a decorator.
When passed a pure functional component, it wraps the function in a classful Component with a shouldComponentUpdate()
that ignores renders for unchanged props.
When passed a classful Component, it injects a shouldComponentUpdate()
method into the Component's prototype that ignores renders for unchanged props & state.
import pure from 'pure-component';
export default pure( props => (
<div>{props.foo}</div>
));
Using it as a decorator:
import pure from 'pure-component';
@pure
export class Foo extends Component {
render({ text }) {
return <div>{text}</div>
}
}
... or as a higher order function:
import pure from 'pure-component';
class Foo extends Component {
render({ text }) {
return <div>{text}</div>
}
}
export default pure(Foo);
Is this still relevant in preact? (Is there now an optimization in preact that makes this obsolete?)