简体   繁体   English

反应本机不变违反错误

[英]React native invariant violation error

I want to implement redux in my react-native app, I imported provider in App.js but when I wrap App content inside <Provider store={store}></Provider> it gives me this error: 我想在我的react-native应用程序中实现redux,我在App.js中导入了提供程序,但是当我将应用程序内容包装在<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}).

I know that I can't render object in return method but what I am supposed to do, how to connect app to redux ? 我知道我不能用return方法渲染对象,但是我应该怎么做,如何将应用程序连接到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>
      );
  }
}

It's commented out now and it works, if I uncomment it it gives the error... 现在已将其注释掉,并且可以正常工作,如果我取消注释,则会出现错误...

I see something is wrong on this line. 我看到这条线有问题。

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

The second parameter is the initial state and you are passing middleware there. 第二个参数是初始状态,您正在其中传递中间件。 See if this can solve it. 看看这是否可以解决。

If that does not solve it, then the problem would be in the Component TavNavigation is rendering. 如果那不能解决问题,那么问题将出在组件TavNavigation正在渲染中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM