Answer the question
In order to leave comments, you need to log in
How to fix `ref` is not a prop error?
Hello everyone, using the following approach, an error occurs.
index.js:1 Warning: [object Object]: `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. (https://fb.me/react-special-props)
import React from "react";
const { useRef, forwardRef } = React;
const ComponentOne = forwardRef((props, ref) => {
return (
<div ref={ref}>
<div>ComponentOne</div>
</div>
);
});
const ComponentTwo = node => {
console.log(node);
return (
<div>
<div>ComponentTwo</div>
</div>
);
};
export const App = () => {
const node = useRef(null);
return (
<div>
<ComponentOne ref={node} />
<ComponentTwo node={node} />
</div>
);
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question