javascript - 反应原生不变违规错误
问题描述
我想在我的 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>
);
}
}
它现在已被注释掉并且它可以工作,如果我取消注释它会给出错误......
解决方案
我看到这条线上有问题。
//const store = createStore(reducer, applyMiddleware(thunk));
第二个参数是初始状态,您正在那里传递中间件。看看这个能不能解决。
如果这不能解决它,那么问题将出在 Component TavNavigation 正在渲染中。
推荐阅读
- c# - Angular 8 post formData 到 ASP.NET Core API 无法绑定 IEnumerable/List
- javascript - 如何解决未捕获的类型错误:无法读取未定义的属性“0”?
- python-3.x - 在不使用全局的情况下从函数内部更改变量
- c# - 为什么我不能在一个表格中获得超过 30 个单元格?
- excel - Excel VBA宏循环“另存为”会增加文件大小?
- python - 如何在Python中程序启动时无边框显示图像(透明)
- jekyll - 为 Jekyll 设置 gemfile - 不清楚出了什么问题
- php - 使用 PHP 编辑 XML 文件
- django - Django:隐藏空单选按钮选项但仍然允许它不为空
- windows - 使用 instsrv.exe 和 srvany.exe 安装服务后无法停止 Windows 服务