简体   繁体   English

Provider中的prop子项无效

[英]Invalid prop children in Provider

I've been learning React for the past several weeks. 过去几周我一直在学习React。
First developed a simple Chat with plain React, and now I started integrating Redux into my app. 首先使用简单的React开发了一个简单的聊天,现在我开始将Redux集成到我的应用程序中。

I added a simple Action, a matching Reducer (along with a root reducer) and a Store. 我添加了一个简单的Action,一个匹配的Reducer(以及一个root reducer)和一个Store。 I then reached the part where I need to use the Provider from the react-redux library: 然后我到达了需要使用react-redux库中的Provider的部分:

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import ConfigureStore from './Store/ConfigureStore';
import Routes from './Routes';

const store = ConfigureStore();
ReactDOM.render(
    <Provider store={store}>
        <Router history={browserHistory}
            routes={Routes} />,
    </Provider>,
    document.getElementById('root')
);

App compiles fine, but I receive the following errors in console: 应用程序编译正常,但我在控制台中收到以下错误:

Warning: Failed prop type: Invalid prop children of type array supplied to Provider , expected a single ReactElement. 警告:失败的prop类型:提供给Provider的类型为array无效prop children项,期望单个ReactElement。 in Provider 在提供者

and

Uncaught Invariant Violation: React.Children.only expected to receive a single React element child. 未捕获的不变违规:React.Children.only预计会收到一个React元素子。

I'm using the React Create App as a starter kit. 我正在使用React Create App作为入门套件。

Full code can be found here . 完整代码可以在这里找到。

You have a , after <Router history={browserHistory} routes={Routes} /> <Router history={browserHistory} routes={Routes} />之后,您有一个

Try removing it? 尝试删除它?

The same error: 同样的错误:

Warning: Failed prop type: Invalid prop children of type array supplied to Provider , expected a single ReactElement. 警告:失败的prop类型:提供给Provider的类型为array无效prop children项,期望单个ReactElement。

Uncaught Error: React.Children.only expected to receive a single React element child. 未捕获的错误:React.Children.only预计会收到一个React元素子元素。

Occurs to me in writing Provider with this format: 使用以下格式编写Provider时发生在我身上:

<Provider store={store}> <App4Connected /> </Provider>

instead the following works correctly: 而是以下工作正常:

<Provider store={store}>
    <App4Connected />
</Provider>

To me writing in this format was throwing error: 对我来说,用这种格式写错了:

ReactDOM.render(<Provider store={store}> <App /> </Provider>, document.getElementById('root'));

But this works fine: 但这很好用:

ReactDOM.render(
    <Provider store={store}> 
        <App /> 
    </Provider>, 
    document.getElementById('root'));

暂无
暂无

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

相关问题 警告:道具类型失败:提供给“提供者”的对象类型为“对象”的道具儿童无效,需要一个ReactElement - Warning: Failed prop type: Invalid prop `children` of type `object` supplied to `Provider`, expected a single ReactElement 反应错误'Failed propType:提供给`Provider`的无效道具`children`,期望一个ReactElement' - React error 'Failed propType: Invalid prop `children` supplied to `Provider`, expected a single ReactElement' React-Redux错误提供给提供者的对象类型为对象的无效子属性prop - React-Redux error Invalid prop `children` of type `object` supplied to `Provider` 道具类型失败:提供给“CSSTransition”的道具“children”无效 - Failed prop type: Invalid prop `children` supplied to `CSSTransition` ReactJs:地图函数中的道具类型无效。 `array` 类型的无效道具 `children` - ReactJs: Invalid prop type in map function. Invalid prop `children` of type `array` 为什么React会说“无效的prop&#39;children&#39;类型是对象不起作用? - Why is React saying “Invalid prop `children`” types is object not function? 获取错误:警告:道具类型失败:提供给“Form”的道具“children”无效,应为 ReactNode - GETTING ERROR : Warning: Failed prop type: Invalid prop `children` supplied to `Form`, expected a ReactNode React Native错误失败的道具类型:提供给`Overlay`的`array`类型的无效道具`children`, - React Native error Failed prop type: Invalid prop `children` of type `array` supplied to `Overlay`, React - 提供给 ButtonBase 的 `component` 属性无效。 请确保在此自定义组件中呈现 children 道具 - React - The `component` prop provided to ButtonBase is invalid. Please make sure the children prop is rendered in this custom component 警告:失败的道具类型:提供给`Dropzone`的类型`string`的prop`child`无效,期望的`function` - Warning: Failed prop type: Invalid prop `children` of type `string` supplied to `Dropzone`, expected `function`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM