๐ก DOM ์๋ฆฌ๋จผํธ ์ฃผ์๊ฐ์ ํ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ
(focus, media play ๋ฑ)
๐ก ์ปดํฌ๋ํธ๊ฐ Re-render๋์ด๋ ๋ฐ๋์ง ์์
๐ก ๋ฆฌ์ํธ๋ ์ ์ธํ ํ๋ก๊ทธ๋จ ์์น์ ๋ฐ๋ฅด๊ธฐ ๋๋ฌธ์ ๋ถ๋์ดํ ์ํฉ์์๋ง ์ฌ์ฉ
๐ focus
import { useRef } from "react";
function x(){
const inputEl = useRef(null);
const handleClick = () => {
inputEl.current.focus();
};
return (
<>
<input ref={inputEl} type="text"/>
<button onClick={handleClick}>a</button>
</>
);
}
๐ video
import { useRef } from "react";
function x(){
const videoEl = useRef(null);
const handlePlay = () => {
videoEl.current.play();
};
const handlePause = () => {
videoEl.current.pause();
};
return (
<>
<video ref={videoEl} controls/>
<source type="video/mp4" src={์์์ฃผ์} />
</video>
<button onClick={handlePlay}>play</button>
<button onClick={handlePause}>pause</button>
</>
);
}