Skip to content

forwardRef causes componentWillReceiveProps after setState #12736

Description

@jamesknelson

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions