React: React.forwardRef - "Element type is invalid" (React Native)

Created on 15 May 2018  路  5Comments  路  Source: facebook/react

Do you want to request a feature or report a bug?
Help with React.forwardRef API / Bug. It's possible this may be an issue with React Native, but I wanted to check here first incase my use of the forwardRef API is incorrect. The docs explain the intent of the API well, but the implementation was a little confusing to me (https://reactjs.org/docs/forwarding-refs.html#forwarding-refs-to-dom-components)

What is the current behavior?

The following code results in an error when executed:

import React from 'react'
import { TextInput } from 'react-native'

const CustomInput = React.forwardRef((props, ref) => {
  return <TextInput {...props} ref={ref} />
})

export default class App extends React.Component {
  render() {
    return <CustomInput />
  }
}

The error reported is:

"Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of 'App'

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

Most helpful comment

Any update on this @gaearon? I get the same issue with ForwardRef with React Native / Typescript on RN 0.57.1 and React 16.8.6

All 5 comments

For reference, this seems to be working in React web/dom OK: https://jsfiddle.net/gx7fn29s/4/

It's not supported in React Native yet.
Next stable version will have it.

@gaearon I am having an issue with styled-components, and someone suggested that it might be because React Native does not support forwardRef ( https://github.com/styled-components/styled-components/issues/2233 ). Is this the case? If so, when would it be supported?

FWIW, I am using React 16.6.1 and React Native 0.57.5

Any update on this @gaearon? I get the same issue with ForwardRef with React Native / Typescript on RN 0.57.1 and React 16.8.6

Hey @gaearon, is there any updates for this yet?

Was this page helpful?
0 / 5 - 0 ratings