“Ссылка в функциональных компонентах” Ответ

Ссылка в функциональных компонентах

function CustomTextInput(props) {
  // textInput must be declared here so the ref can refer to it  const textInput = useRef(null);  
  function handleClick() {
    textInput.current.focus();  }

  return (
    <div>
      <input
        type="text"
        ref={textInput} />      <input
        type="button"
        value="Focus the text input"
        onClick={handleClick}
      />
    </div>
  );
}
Cheerful Cat

Ссылка в функциональных компонентах

function MyFunctionComponent() {  return <input />;
}

class Parent extends React.Component {
  constructor(props) {
    super(props);
    this.textInput = React.createRef();  }
  render() {
    // This will *not* work!
    return (
      <MyFunctionComponent ref={this.textInput} />    );
  }
}
Cheerful Cat

Ответы похожие на “Ссылка в функциональных компонентах”

Вопросы похожие на “Ссылка в функциональных компонентах”

Больше похожих ответов на “Ссылка в функциональных компонентах” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования