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);
}
};