“Comment utiliser Useref Hook in React” Réponses codées

useRef () in React

function TextInputWithFocusButton() {
  const inputEl = useRef(null);
  const onButtonClick = () => {
    // `current` points to the mounted text input element
    inputEl.current.focus();
  };
  return (
    <>
      <input ref={inputEl} type="text" />
      <button onClick={onButtonClick}>Focus the input</button>
    </>
  );
}
Salo Hopeless

Comment utiliser Useref Hook in React

import React, { useRef } from 'react';

function TextInputWithFocusButton() {
  const inputEl = useRef(null);
  const onButtonClick = () => {
    // `current` points to the mounted text input element
    inputEl.current.focus();
  };
  return (
    <>
      <input ref={inputEl} type="text" />
      <button onClick={onButtonClick}>Focus the input</button>
    </>
  );
}
Blushing Beaver

Qu'est-ce que Useref réagit

const refContainer = useRef(initialValue);
//useRef returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). 
//The returned object will persist for the full lifetime of the component.
Happy Hamster

Réponses similaires à “Comment utiliser Useref Hook in React”

Questions similaires à “Comment utiliser Useref Hook in React”

Plus de réponses similaires à “Comment utiliser Useref Hook in React” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code