반응형
화살표는 비동기 기능과 함께 반응하여 네이티브 대기
데이터를 저장하려고 하는 경우AsyncStorage
에react-native
비동기식으로 저장해서async
그리고await
키워드
async onPositiveClickListener = () => {
// user has completed product tour_end
try {
await AsyncStorage.setItem("@ProductTour:key", "true");
const { navigate } = this.props.navigation;
navigate("DashboardScreen");
} catch (error) {
console.log(error);
}
};
프로그램을 저장하는 중 오류가 발생함
SyntaxError: Unexpected token, expected ( (40:32)
38 | };
39 |
> 40 | async onPositiveClickListener = () => {
| ^
41 | // save user has completed product tour_end
42 | try {
43 | await AsyncStorage.setItem("@ProductTour:key", "true");
Hide Stack Trace
SyntaxError: Unexpected token, expected ( (40:32)
38 | };
39 |
> 40 | async onPositiveClickListener = () => {
| ^
41 | // save user has completed product tour_end
42 | try {
비동기 명명 화살표 함수는 다음과 같이 선언되어야 한다.
const onPositiveClickListener = async () => {
// user has completed product tour_end
try {
await AsyncStorage.setItem("@ProductTour:key", "true");
const { navigate } = this.props.navigation;
navigate("DashboardScreen");
} catch (error) {
console.log(error);
}
};
참조URL: https://stackoverflow.com/questions/43718103/arrow-functions-with-async-and-await-in-react-native
반응형
'programing' 카테고리의 다른 글
vue 구성 요소에 대한 루프가 완료된 후 어떻게 문 또는 메소드를 호출할 수 있는가? (0) | 2022.03.08 |
---|---|
구성 요소의 메서드를 사용하여 vue의 소품 값을 변경하려면 어떻게 해야 하는가? (0) | 2022.03.08 |
Vue.js/Vuetify - 다른 선택 항목을 기준으로 선택 데이터 필터링 (0) | 2022.03.08 |
Native(원본 반응) (0) | 2022.03.08 |
웹 뷰에서 터치가 Apple Pencle인지 핑거인지 탐지(원본 리액트) (0) | 2022.03.08 |