简体   繁体   English

反应错误'Failed propType:提供给`Provider`的无效道具`children`,期望一个ReactElement'

[英]React error 'Failed propType: Invalid prop `children` supplied to `Provider`, expected a single ReactElement'

i have some problem with React.js. 我有一些React.js的问题。 this is my code: 这是我的代码:

import React from 'react';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import App from './containers/App';
import todoApp from './reducers';

let store = createStore(todoApp);
let rootElement = document.getElementById('root');

React.render(
    <Provider store={store}>
        {() => <App />}
    </Provider>,
    rootElement
);

and runs the page, it saids: 并运行页面,它说:

Failed propType: Invalid prop children supplied to Provider , expected a single ReactElement propType失败:提供给Provider无效prop children ,预期单个ReactElement

this is the list of my related installed node modules: 这是我相关的已安装节点模块的列表:

  • react 15.0.1 反应15.0.1
  • react-redux 4.4.5 react-redux 4.4.5
  • redux 3.4.0 redux 3.4.0

actually, i am currently learning React with Redux, so it is hard to me how should i do. 实际上,我目前正在学习与Redux的React,所以我很难怎么做。 i just followed tutorial on website(i can give a link, but it is not english) but it is just not working with that error message. 我只是按照网站上的教程(我可以提供一个链接,但它不是英文)但它只是没有使用该错误消息。 as i searched, someone said upgrade version of react and react-redux, but i installed latest versions. 当我搜索时,有人说反应和react-redux的升级版本,但我安装了最新版本。 any advice will be very appreciate it. 任何建议都会非常感激。

According to the doc , you can just use a normal React element instead of a function inside <Provider /> . 根据文档 ,您可以使用普通的React元素而不是<Provider />中的函数。

As a result, simply change your code to 因此,只需将代码更改为

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

I think this has changed since react@0.14. 我认为自react@0.14以来这已经发生了变化。

The original question had a typo. 最初的问题有一个错字。 Your response is correct in the proper syntax. 您的响应在正确的语法中是正确的。

However, the direct reason is that <App /> needs to be on a separate line. 但是,直接原因是<App />需要在一个单独的行上。

If you put it on the same line as <Provider store={store}> React/Redux tries to do more with it than it should. 如果你把它放在与<Provider store={store}>相同的行上,React / Redux会尝试用它做更多的事情。

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

I was brought to this and I simply forgot to provide a prop. 我被带到了这里,我只是忘了提供道具。 I would say make sure that you are providing all the props that your component is using and that should fix it. 我会说确保您提供组件正在使用的所有道具并且应该修复它。

暂无
暂无

声明:本站的技术帖子网页,遵循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 失败的道具类型:提供给`Body`的无效道具&#39;app`,期望一个ReactElement - Failed prop type: Invalid prop `app` supplied to `Body`, expected a single ReactElement 警告:propType失败:使用React的类型为`array` expected`object`的prop - Warning: Failed propType: Invalid prop of type `array` expected `object` with React 获取错误:警告:道具类型失败:提供给“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`, 提供给叠加层的“数组”类型的道具“子项”无效。 期望单个反应元素 - Invalid prop 'children' of type 'array' supplied to overlay. Expected a single react element React-Redux错误提供给提供者的对象类型为对象的无效子属性prop - React-Redux error Invalid prop `children` of type `object` supplied to `Provider` 警告:道具类型失败:提供给“路线”的道具“组件”无效 - Warning: Failed propType: Invalid prop 'component' supplied to 'route' 警告:propType失败:提供给“ LaptopHandling”的类型为“ function”的无效prop`swimmingSnapshot`, - Warning: Failed propType: Invalid prop `swimmingSnapshot` of type `function` supplied to `LaptopHandling`, 警告:propType失败:提供给`sportsMockUpStandard`的无效道具`rrrr` - Warning: Failed propType: Invalid prop `rrrr` supplied to `sportsMockUpStandard`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM