【问题标题】:React Native Calendar returns {"_U":0,"_V":0,"_W":null,"_X":null}, not awaiting a promiseReact Native Calendar 返回 {"_U":0,"_V":0,"_W":null,"_X":null},不等待承诺
【发布时间】:2021-11-26 02:14:19
【问题描述】:

我正在使用 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));
      }
    })();
  }, []);

【问题讨论】:

  • 不是const events = await Calendar.getEventsAsync吗?
  • 你为什么照原样调用then,而在里面什么也不做?您应该在 then 中使用回调的结果或使用 await,但不能同时使用。
  • 那是一个错字,我把它改掉了。

标签: javascript react-native async-await expo


【解决方案1】:

{"_U":0,"_V":0,"_W":null,"_X":null} 这可能是因为你没有在 之前添加 await 关键字>Calendar.getEventsAsync !!

【讨论】:

  • 当我使用 await 这似乎解决了这个问题,但后来我收到带有参数的ExpoCalendar.getEventsAsync `(]......这可能是因为发送的参数吗?
  • 你收到带有参数 `(]>> 的
  • 我将整个错误添加到问题正文中
  • 这可能是由于 expo-calendar 的安装方式造成的吗?
  • @Ikhadir 我解决了另一个问题,谢谢!
猜你喜欢
  • 2022-01-14
  • 2021-03-02
  • 2022-01-14
  • 2022-01-05
  • 2021-04-21
  • 1970-01-01
  • 1970-01-01
  • 2021-12-20
相关资源
最近更新 更多