React-Class Ref
914 단어 React-ClassReact-Class
설명
- ref는 걍 Html Id랑 비슷함. 컴포넌트 별로 지정하는 Id.
state = { text: '' }
// 버튼 클릭하면 ref로 인풋 불러와서 값 출력함.
handleClick = (e) => {
console.log(this.textInput.value);
}
<button onClick={this.handleClick}></button>
// input 값 업데이트
handleChange = (e) => {
this.setState({ text: e.target.value });
}
<input
type="text"
value={this.state.text}
onChange={this.handleChange}
ref={(ref) => {this.textInput=ref}} // ref 지정하는 방법
/>
Author And Source
이 문제에 관하여(React-Class Ref), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@y37653/React-Class-Ref저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)