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

modernator picture modernator · Apr 20, 2016 · Viewed 74.7k times · Source

i have some problem with 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

this is the list of my related installed node modules:

  • react 15.0.1
  • react-redux 4.4.5
  • redux 3.4.0

actually, i am currently learning React with Redux, so it is hard to me how should i do. 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. any advice will be very appreciate it.

Answer

wuct picture wuct · Apr 20, 2016

According to the doc, you can just use a normal React element instead of a function inside <Provider />.

As a result, simply change your code to

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

I think this has changed since [email protected].