React Native Calendar returns {"_U":0,"_V":0,"_W":null,"_X":null},不等待承诺
React Native Calendar returns {"_U":0,"_V":0,"_W":null,"_X":null}, not awaiting a promise
我正在使用 expo-calendar 并从用户的设备中检索日历对象。
收到日历后,我正在使用日历从各个日历中检索事件。
请求事件后,我在记录请求的事件数据时收到 {"_U":0,"_V":0,"_W":null,"_X":null}
。
除此之外,我还收到错误消息:[Unhandled promise rejection: Error: An exception was thrown while calling `ExpoCalendar.getEventsAsync` with arguments `(] at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper at node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name at http://127.0.0.1:19000/index.bundle?platform=ios&dev=true&hot=false&minify=false:321320:82 in getEventsAsync$ at Screens/Tasks_1.js:1018:15 in <global>
我认为这是因为请求 const events = Calendar.getEventsAsync()
正在等待承诺,但我无法确定它在等待什么响应。如何正确访问事件?
useEffect(() => {
(async () => {
//REQUEST PERMISSION TO ACCESS CALENDAR
const { status } = await Calendar.requestCalendarPermissionsAsync();
if (status === "granted") {
const calendars = await Calendar.getCalendarsAsync(
Calendar.EntityTypes.EVENT
);
//LIST OF ALL CALENDARS ON DEVICE WITH ID's
console.log("Here are all your calendars:");
console.log({ calendars });
//GET EVENTS FROM A CALENDAR ON DEVICE WITH A GIVEN ID AND TIME RANGE
const events = Calendar.getEventsAsync(
calIDs,
"2021-04-14T17:00:00.00Z",
"2021-09-14T17:00:00.00Z"
);
//THIS LOGS {"_U":0,"_V":0,"_W":null,"_X":null}
console.log("EVENTS" + JSON.stringify(events));
}
})();
}, []);
{"_U":0,"_V":0,"_W":null,"_X":null} 发生这种情况可能是因为您没有添加 await 关键字在 Calendar.getEventsAsync !!
之前
我正在使用 expo-calendar 并从用户的设备中检索日历对象。
收到日历后,我正在使用日历从各个日历中检索事件。
请求事件后,我在记录请求的事件数据时收到 {"_U":0,"_V":0,"_W":null,"_X":null}
。
除此之外,我还收到错误消息:[Unhandled promise rejection: Error: An exception was thrown while calling `ExpoCalendar.getEventsAsync` with arguments `(] at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper at node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name at http://127.0.0.1:19000/index.bundle?platform=ios&dev=true&hot=false&minify=false:321320:82 in getEventsAsync$ at Screens/Tasks_1.js:1018:15 in <global>
我认为这是因为请求 const events = Calendar.getEventsAsync()
正在等待承诺,但我无法确定它在等待什么响应。如何正确访问事件?
useEffect(() => {
(async () => {
//REQUEST PERMISSION TO ACCESS CALENDAR
const { status } = await Calendar.requestCalendarPermissionsAsync();
if (status === "granted") {
const calendars = await Calendar.getCalendarsAsync(
Calendar.EntityTypes.EVENT
);
//LIST OF ALL CALENDARS ON DEVICE WITH ID's
console.log("Here are all your calendars:");
console.log({ calendars });
//GET EVENTS FROM A CALENDAR ON DEVICE WITH A GIVEN ID AND TIME RANGE
const events = Calendar.getEventsAsync(
calIDs,
"2021-04-14T17:00:00.00Z",
"2021-09-14T17:00:00.00Z"
);
//THIS LOGS {"_U":0,"_V":0,"_W":null,"_X":null}
console.log("EVENTS" + JSON.stringify(events));
}
})();
}, []);
{"_U":0,"_V":0,"_W":null,"_X":null} 发生这种情况可能是因为您没有添加 await 关键字在 Calendar.getEventsAsync !!
之前