首页 > 解决方案 > 反应原生不变违规错误

问题描述

我想在我的 react-native 应用程序中实现 redux,我在 App.js 中导入了提供程序,但是当我将 App 内容包装在其中时,<Provider store={store}></Provider>它给了我这个错误:

Invariant Violation: Objects are not valid as a React child (found: object with .... object with keys {$$typeof, type, key, ref, props, _owner, _store}).

我知道我不能在 return 方法中渲染对象,但是我应该做什么,如何将 app 连接到 redux ?

import React, { Component } from 'react';

import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';

// import reducer from './reducers/index';

import TabNavigation from './navigation/TabNavigation';
import StackNavigation from './navigation/StackNavigation';

//const store = createStore(reducer, applyMiddleware(thunk));

export default class App extends React.Component{

  render() {
    return (
    //<Provider store={store}>
        <TabNavigation />
      //</Provider>
      );
  }
}

它现在已被注释掉并且它可以工作,如果我取消注释它会给出错误......

标签: javascriptreactjsreact-nativerender

解决方案


我看到这条线上有问题。

//const store = createStore(reducer, applyMiddleware(thunk));

第二个参数是初始状态,您正在那里传递中间件。看看这个能不能解决。

如果这不能解决它,那么问题将出在 Component TavNavigation 正在渲染中。


推荐阅读