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

forwardRef causes componentWillReceiveProps after setState #12736

Closed
jamesknelson opened this issue May 3, 2018 · 2 comments
Closed

forwardRef causes componentWillReceiveProps after setState #12736

jamesknelson opened this issue May 3, 2018 · 2 comments

Comments

@jamesknelson
Copy link

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When inside of a forwardRef, calling setState causes componentWillReceiveProps to be called after the setState has completed.

See https://codesandbox.io/s/n59k2v25r0 for demo

What is the expected behavior?

The docs don't seem to forbid this behavior ("Calling this.setState() generally doesn’t trigger UNSAFE_componentWillReceiveProps()."), so I'm not sure this is technically a bug.

However, it does cause older code that doesn't yet use the reducer syntax for setState to stop working when wrapped in forwardRef. It caused a few headscratchers for me while refactoring old code, so I'm reporting it just in case.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

This appears in 16.3.2. Given that it is specific to forwardRef, it shouldn't apply to older versions.

@gaearon
Copy link
Collaborator

gaearon commented May 3, 2018

Pretty sure #12690 fixed this on master.

@gaearon gaearon closed this as completed May 3, 2018
@gaearon
Copy link
Collaborator

gaearon commented May 24, 2018

Should be fixed in React 16.4.
https://reactjs.org/blog/2018/05/23/react-v-16-4.html

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

No branches or pull requests

2 participants