EvgenBabenko / incode-app

0 stars 0 forks source link

avoid componentDidUpdate as much as possible #10

Open olegmdev opened 6 years ago

olegmdev commented 6 years ago

https://github.com/EvgenBabenko/incode-app/blob/fb46fcbc976556e7cb5365795405f511edad92f6/src/containers/Dashboard.jsx#L21

Try to avoid componentDidUpdate as much as possible. Use it only in case you need to do something after EVERY component rerender (DOM has been updated): for example you're using any 3rd-party UI libs like charts, maps or whatever. There is a recommendation to use it in case you need some actions to perform if props have been changed, but it's also dangerous bc you may come into an infinite loop by occasional using setState somewhere inside. Please take a look at getDerivedStateFromProps approach https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops AND read about it thoughtfully (including warnings and better alternatives).