我想在我的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}).
我知道我无法在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>
);
}
}
它已被注释掉并且可以正常工作,如果我取消注释,它会给出错误信息...
答案 0 :(得分:0)
我看到这行有问题。
// const store = createStore(reducer,applyMiddleware(thunk));
第二个参数是初始状态,您正在其中传递中间件。看看这是否可以解决。
如果那不能解决问题,那么问题就出在组件TavNavigation正在渲染。