H
H
Hlib2019-06-08 22:28:18
JavaScript
Hlib, 2019-06-08 22:28:18

How to pass ref through props?

There was a problem of passing through props
. We have a certain Input component.
It is needed for a simplified layout of the page
. Props are passed to it, including the need to somehow pass ref
How to do this?
Already tried through the state and through assigning a value to a variable from props
Gives an error:
index.js:1375 Warning: Input: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LEXA_JA, 2019-06-08
@Mysianio

You need to use forwardRef or pass the ref under a different name.
Link to Documentation

const Input = forwardRef((props, ref) => <input ref={ref} {...props}  />)

const Input = ({  inputRef, ...props }) => <input ref={inputRef} {...props} />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question