Skip to content

Instantly share code, notes, and snippets.

@reireynoso
Last active October 14, 2020 01:18
Show Gist options
  • Save reireynoso/16801671fc1c7ca63b2ec8f8bfbdc674 to your computer and use it in GitHub Desktop.
Save reireynoso/16801671fc1c7ca63b2ec8f8bfbdc674 to your computer and use it in GitHub Desktop.
Another component forward ref sample
import React from 'react'
const AnotherComponent = React.forwardRef((props, ref) => {
return (
<h1>Another Component</h1>
<input type="text" ref={ref} />
)
})
export default AnotherComponent
@sudarshan-kj
Copy link

sudarshan-kj commented Oct 14, 2020

@reireynoso The content inside return statement is invalid jsx. You need to wrap the above two children in a fragment or a div like so:

return ( 
     <>
       <h1>Another Component</h1>
       <input type="text" ref={ref} />
      </>
  )

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