Показать сообщение отдельно
  #1 (permalink)  
Старый 19.05.2020, 10:12
Аспирант
Отправить личное сообщение для dc65k Посмотреть профиль Найти все сообщения от dc65k
 
Регистрация: 19.05.2020
Сообщений: 46

Как исправить ошибку `ref` is not a prop в React.js ?
Всем привет, используя следующий подход, возникает ошибка.
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. ([url]https://fb.me/react-special-props[/url])

Подскажите пожалуйста как правильно её исправить ?
https://reactjs.org/docs/forwarding-refs.html
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>
  );
};

Последний раз редактировалось dc65k, 19.05.2020 в 10:15.
Ответить с цитированием