“Cara Menggunakan Useref Hook di React” Kode Jawaban

useref () dalam bereaksi

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

Cara Menggunakan Useref Hook di 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

Apa yang Useref lakukan reaksi

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

Jawaban yang mirip dengan “Cara Menggunakan Useref Hook di React”

Pertanyaan yang mirip dengan “Cara Menggunakan Useref Hook di React”

Lebih banyak jawaban terkait untuk “Cara Menggunakan Useref Hook di React” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya