TypeError: Cannot read property ‘getState’ of undefined
If we look inside react-redux <Provider />
<Provider />
expects to be provided a store
prop:
this.state = { storeState: store.getState(), ^^here store }
Hence the error.
You can create one, though, using a reducer, should be something similar to this:
import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import reducer from './reducer'
import App from './components/App'
const store = createStore(reducer)
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
You need to add a store to your provider.
If you don't have any reducer, you can add a dummy reducer.
Assume that the dummy reducer returns an empty array.
() => []
So, your code will be changed to:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
const store = createStore(() => [], {}, applyMiddleware());
import './index.css';
const App = () => (<div>Hi </div>);
ReactDOM.render(<Provider store={store}><App /></Provider>,
document.getElementById('root'));