Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning about componentWillReceiveProps in React's Strict Mode #624

Open
ulrichb opened this issue Mar 16, 2019 · 9 comments · May be fixed by #735
Open

Warning about componentWillReceiveProps in React's Strict Mode #624

ulrichb opened this issue Mar 16, 2019 · 9 comments · May be fixed by #735

Comments

@ulrichb
Copy link

ulrichb commented Mar 16, 2019

React's Strict Mode warns about "Unsafe lifecycle methods were found within a strict-mode tree".

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

componentWillReceiveProps(nextProps) {
if (shallowEqualArrays(nextProps.suggestions, this.props.suggestions)) {
if (
nextProps.highlightFirstSuggestion &&
nextProps.suggestions.length > 0 &&
this.justPressedUpDown === false &&
this.justMouseEntered === false
) {
this.highlightFirstSuggestion();
}
} else {
if (this.willRenderSuggestions(nextProps)) {
if (this.state.isCollapsed && !this.justSelectedSuggestion) {
this.revealSuggestions();
}
} else {
this.resetHighlightedSuggestion();
}
}
}

@ulrichb
Copy link
Author

ulrichb commented Aug 9, 2019

Now with React 16.9 it's even a non-strict mode warning ...

@Kove11
Copy link

Kove11 commented Aug 12, 2019

Any update on this @moroshko ?

@ghost
Copy link

ghost commented Sep 30, 2019

Still very relevant, looking forward to updates

@rlueder
Copy link

rlueder commented Oct 23, 2019

Here's a PR that should take care of it: #681

@aberezkin
Copy link
Collaborator

aberezkin commented Mar 17, 2020

Fixed in #681

@wzijden
Copy link

wzijden commented Apr 9, 2020

@aberezkin this should not have been closed. It resolves #670, but not this one. A warning is still shown in React's strictmode:

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code.

@aberezkin
Copy link
Collaborator

Can someone work on this?

@aberezkin aberezkin added api and removed api labels Apr 12, 2020
lregla added a commit to lregla/react-autosuggest that referenced this issue Jan 12, 2021
lregla added a commit to lregla/react-autosuggest that referenced this issue Jan 12, 2021
lregla added a commit to LexMachinaInc/react-autosuggest that referenced this issue Jan 12, 2021
* Catch-up master branch to upstream tag 10.1.0
* updated .gitignore for IDE config
* moroshko#624 Refactor to move code out of deprecated componentWillRecieveProps
* moroshko#624 Refactor to move code out of deprecated componentWillRecieveProps in Autowhatever component
lregla added a commit to LexMachinaInc/react-autosuggest that referenced this issue Jan 12, 2021
* updated .gitignore for IDE config

* moroshko#624 Refactor to move code out of deprecated componentWillRecieveProps

* moroshko#624 Refactor to move code out of deprecated componentWillRecieveProps in Autowhatever component
@adi518
Copy link

adi518 commented Jul 27, 2021

Fixed in #681

It doesn't fix this warning for strict mode. To fix this issue the implementation has to change to this lifecycle: https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops.

Links from the snippet below:

index.js:1 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://reactjs.org/link/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://reactjs.org/link/derived-state

Please update the following components: Autosuggest, Autowhatever

@reft
Copy link

reft commented Sep 20, 2021

still not fixed¿¿

image

QQ

"react": "^17.0.2",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants