Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- react-native
- C++98에러
- touchableopacity
- fcm push
- fcm 푸시
- ReactNative
- 알고리즘
- 순열
- 자동로그인
- 가격자릿수
- React
- 모달에서뒤로가기
- Flatlist
- 2023년 정처기 필기
- 리액트네이티브
- 재귀함수
- makePermutation
- JSON
- vision-camera
- modal
- 모달
- API
- TextInput
- 뒤로가기구현
- 페이지리렌더링
- asyncstorage
- algorithm
- 리액트
- 리액트 네이티브
- Icon
Archives
- Today
- Total
생각은 길게 코딩은 짧게
[React-Native] 유효성 검사 후 포커스 이동 ( class component ) 본문
728x90
함수형 자료가 너무 많은데에 비해 class형은 자료가 많이 없어서 헤맷다 ... 이러한 삽질은 좋지 않으므로 포스팅 해야징
✅ UseRef를 class형에서 쓰는 방법 ( 출처 - stack overflow )
this.myRef = React.createRef();
요렇게 React.UseRef를 사용하면 된다
비전 카메라 구현했을 때도 이렇게 했는데... 제대로 알고 쓰지 않으면 이렇게 되는 것이다... 뭐든지 제대로 해야함!!
✅ 적용코드
constructor(props) {
super(props);
this.nameRef = React.createRef();
}
handleModal = () => {
const { name ,number,price } = this.state ;
if (name == ""){
this.nameRef.focus();
Alert.alert("입력 항목을 확인해주세요");
return false;
}
}
<TextInput style={template.textInput}
ref = {(c) => {this.nameRef = c;}}
onChangeText={name => this.onEnterName(name)}
placeholder="품명을 입력하세요."
/>
상품등록 버튼을 눌렀을 때 textInput이 비었을 경우 경고 메세지와 함께 focus를 해당하는 항목으로 이동되게 구현하였다.
'React Native' 카테고리의 다른 글
[React-Native] FlatList 새로고침 ( Page Refresh ) (0) | 2022.11.18 |
---|---|
[React-Native] <Text> 글자 수 제한하기 (0) | 2022.11.17 |
[React-Native] 키보드에 하단 TabBar 숨기기 (0) | 2022.11.17 |
[React-Native] Props로 받은 값으로 Modal 구현하기 (0) | 2022.11.15 |
[React-Native] Linking 을 활용한 구글 웹페이지 열기 (0) | 2022.11.15 |