Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PureComponent decorated by mobx-react throws error about `shouldComponentUpdate` presence

In console I see this warning:

index.js:2178 Warning: Body has a method called shouldComponentUpdate(). shouldComponentUpdate should not be used when extending React.PureComponent. Please extend React.Component if shouldComponentUpdate is used.

Body component is using

...
import { observer, inject } from 'mobx-react';
...
@inject('store')
@observer
class Body extends React.PureComponent<BodyProps> {
...

but doesn't have this shouldComponentUpdate method anywhere.

Is this coming from mobx-react? Can I use PureComponent in components decorated by @observable or @inject ?

like image 487
zmii Avatar asked Apr 27 '18 11:04

zmii


1 Answers

PureComponents should not be used in combination with observer. Conceptually it is strange as observer makes components impure; as they can update without prop changes (which is actually the whole point of observer).

The upcoming mobx-react version will warn about this :)

like image 84
mweststrate Avatar answered Sep 28 '22 12:09

mweststrate