๐ย Reference
๐ย Chapter
์์ 1
class AutoFocusTextInput extends React.Component {
constructor(props) {
super(props);
this.textInput = React.createRef();
}
componentDidMount() {
this.textInput.current.focusTextInput();
}
render() {
return (
<CustomTextInput ref={this.textInput} />
);
}
}
ref
์ฌ์ฉ์ด ์์ ๋์ง ์๋๋ค๋ ๊ฒ์ ์๋๋ค.HTMLElement
์๋ ref
๋ฅผ ์ฌ์ฉํ ์ ์๋ค.function CustomTextInput(props) {
// textInput์ ref ์ดํธ๋ฆฌ๋ทฐํธ๋ฅผ ํตํด ์ ๋ฌ๋๊ธฐ ์ํด์
// ์ด๊ณณ์์ ์ ์๋์ด์ผ๋ง ํฉ๋๋ค.
const textInput = useRef(null);
function handleClick() {
textInput.current.focus();
}
return (
<div>
<input
type="text"
ref={textInput} />
<input
type="button"
value="Focus the text input"
onClick={handleClick}
/>
</div>
);
}