【问题标题】:ReactNative expo app crna entry Bundle exception after redux state dispatchReactNative expo app crna entry Bundle异常后redux状态分派
【发布时间】:2018-08-23 00:42:47
【问题描述】:

我不知道如何调用这个奇怪的异常,因为我的控制台上打印的异常消息没有给出任何提示和任何有意义的消息。因此,我无法为异常设置适当的标题。

该应用是使用 Expo 和 Redux 状态管理器开发的 调度状态后,我收到以下异常。

有趣的观察:

  1. 该操作是适当的,并且有效负载具有有效的 JSON 值。

  2. 当我在 reducer 中打印有效负载时,它正在打印正确的值

这里是代码

axios.post('API PATH', reqBody)
  .then(response => {
      dispatch({
        type: CAMPAIGNS_FETCH_SUCCESS,
        payload: response.data.campaigns
      });
  })
  .catch(error => {
    console.error('error occured while fetching campaigns: ', JSON.stringify(error));
  });

对于上面的代码,一旦我将控件发送到reducer 并且reducer 正在打印正确的值,但之后我得到以下异常

    error occured while fetching campaigns: , {"line":163362,"column":43,"sourceURL":"http://packager.kk.camp.exp.direct:80/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false"}
- node_modules/react-native/Libraries/ReactNative/YellowBox.js:67:16 in error
* src/screens/CampaignActions/
CampaignActions.js:125:22 in <unknown>
- node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
- node_modules/promise/setimmediate/core.js:123:25 in <unknown>
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:295:23 in <unknown>
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:148:6 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:196:17 in _callImmediatesPass
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:464:11 in callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:282:4 in __callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:137:6 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:269:6 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:136:17 in flushedQueue
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:11 in callFunctionReturnFlushedQueue

有什么帮助吗?这对我来说需要很多时间。

【问题讨论】:

  • 在你做的时候分派payload是很危险的。 response.data 可以是未定义的,所以会抛出错误。您应该在调度此操作之前检查您是否真的有 response.data

标签: react-native redux react-redux react-native-android


【解决方案1】:

我找到了解决方案,但不确定一些事情,让我把它放在这里,期待一些cmet进一步理解。

我有两个组件,比如 Component1 和 Component2 ,每个都有自己的状态,比如 ComponentState1 和 ComponentState2 以及两个减速器 ComponentReducer1 和 ComponentReducer2。

在我的两个州都有一个共同的 json 数组,比如 Campaigns[] 在两个组件州中都很常见。当我加载 Component2 时它崩溃了,然后我从 Component1 中删除了活动的操作,这意味着 ComponentReducer1 和 ComponentReducer2 都有一个共同的操作,比如 Campaign_Fetch_Success,我从 Component1 中删除了它,然后崩溃就解决了,但是我也需要 Component1 中的活动我发送了不同的操作,只有在加载 component1 时才会发送,比如 Campaign_Fetch_For_Component1_Success。

现在问题已经解决了,但是为什么当我们对两个组件减速器采取相同的操作时它会崩溃,这让我仍然感到困惑?

【讨论】:

    猜你喜欢
    • 2020-11-09
    • 2020-04-22
    • 2021-05-02
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 2018-06-25
    相关资源
    最近更新 更多