“Cómo usar el gancho Useref en React” Código de respuesta

useref () en 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

Cómo usar el gancho Useref en 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é reacciona Useref?

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

Respuestas similares a “Cómo usar el gancho Useref en React”

Preguntas similares a “Cómo usar el gancho Useref en React”

Más respuestas relacionadas con “Cómo usar el gancho Useref en React” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código