[英]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 toProvider
, expected a single ReactElementpropType失败:提供给
Provider
无效propchildren
,预期单个ReactElement
this is the list of my related installed node modules: 这是我相关的已安装节点模块的列表:
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.