import { useRef } from "react";
const Component = () => {
const buttonRef = useRef<HTMLButtonElement>(null);
return <button ref={buttonRef}>Hello</button>;
};
νμ μ¨μλ λ°©μμ ref μ νΈλ²ν΄μ ν΄λΉνλ νλ‘νΌν°λ₯Ό νμΈνλ λ°©μμ΄μλ€.
ElementRef
ElementRef λ₯Ό μ¬μ©νλ©΄ μ‘°κΈ λ μ½κ² μ¬μ©ν μ μλ€κ³ νλ€. π
import { useRef, ElementRef } from "react";
const Component = () => {
const buttonRef = useRef<ElementRef<"button">>(null);
return <button ref={buttonRef}>Hello</button>;
};
typeof λ μ¬μ©κ°λ₯!
μ΄λ―Έ μ΄μ λ²μ μ μ¬μ©νκ³ μλ€λ©΄ κ΅³μ΄ ElementRef λ‘ λ³κ²½ν νμλ μλ€!
https://www.totaltypescript.com/strongly-type-useref-with-elementref
μ€λλ§μ λ€μ΄μλ€κ° 3μμ΄ λ§μ§λ§ κΈμΈ κ²μ νμΈνκ³ ..κ°λ¨νκ² νλ μ μ΄λ³΄μλ€!π₯Ή
'π WIL > π TypeScript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π‘ TypeScript μ¬μ©ν νκΈ° (0) | 2022.08.12 |
---|---|
Props.children νμ μ§μ ? (0) | 2022.08.09 |