Skip to content

typeof React.forwardRef(...) is not a 'function', breaking third-party libs #12453

Closed
@jamesreggio

Description

@jamesreggio

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

Bug, possibly

What is the current behavior?

The new React.forwardRef feature returns an object, not a function.

To this point, the typeof both stateless components and class components was 'function'.

React does not expose a utility to check whether a given value is valid to be passed to React.createElement. As a result, third-party library authors who wish to pre-validate a component type will commonly use typeof Component === 'function' to test whether the type is valid. The return value of forwardRef, despite being a valid component type, will fail this naive test. Library authors do this in order to provide better errors than would otherwise be provided by React if an invalid component type was passed in.

In a perfect world, the fault would fall squarely on the third-party library developers for using an imprecise check, but those developers could rightfully point out that React has given them little ability to be precise in these pre-emptive checks.

This is one of those "don't break the internet" bugs. This is a bug where third-party developers have taken reasonable-yet-illegal dependencies on React internals in order to provide a better experience for their users. If it's not too difficult, it may be a good idea to chane forwardRef to return a 'function', instead of an object.

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

React 16.3.0-alpha.3

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