React-select: Feature request: Remove deprecated componentWillReceiveProps life cycle method

Created on 9 Nov 2018  路  4Comments  路  Source: JedWatson/react-select

React.StrictMode emits a warning about componentWillReceiveProps in Select and its children.

It looks like all uses of componentWillReceiveProps can be trivially replaced with componentDidUpdate, at the minor cost of potential double-renders when certain props change. Could use getDerivedStateFromProps instead, but that causes more problems than it's worth IMO.

If I can find the time, I might open a PR for this.

Most helpful comment

@JedWatson is this supposed to have been fixed in 3.0.8? I'm still getting this warning:

index.js:1437 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state

Please update the following components: AutosizeInput, Select

All 4 comments

The warning this generates is of form (to assist searching issues):

Warning: Unsafe lifecycle methods were found within a strict-mode tree:
    in StrictMode (at foo/index.jsx:28)

componentWillReceiveProps: Please update the following components to use
static getDerivedStateFromProps instead: Select

The offending usage is here:
https://github.com/JedWatson/react-select/blob/ed823a8dde92374a950f09f4b439b673de0ac2c1/src/Select.js#L388-L411
(though there are others in the repo: https://github.com/JedWatson/react-select/search?q=componentWillReceiveProps)

React docs on migrating:
https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#migrating-from-legacy-lifecycles
https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops

@edmorley this is on our roadmap, but if you have the time, a PR would be greatly appreciated 馃憤

Closing the loop here: we've made sure there are no deprecation warnings in the most recent version, and this is fine for React 16.x

We're looking at shifting away from lifecycle methods (hooks!) but it's a pretty big task to undertake so will land with v4 and go through the same alpha / beta / stable release process we used for v2 so as to minimise risk for users.

@JedWatson is this supposed to have been fixed in 3.0.8? I'm still getting this warning:

index.js:1437 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state

Please update the following components: AutosizeInput, Select
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pablote picture pablote  路  3Comments

steida picture steida  路  3Comments

juliensnz picture juliensnz  路  3Comments

mbonaci picture mbonaci  路  3Comments

MindRave picture MindRave  路  3Comments