I followed the instructions and created the store from this library
https://github.com/jesperorb/redux-cart
src/store/index.js:
import { createStore } from 'redux';
//Import our rootreducer from '../reducers/index.js' this hold our whole state
import rootReducer from '../reducers/index.js';
/**
* @param {Object} initialState
*/
export default function store() {
return createStore(
rootReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
}
```
src/actions/cart-actions.js:
/** We don't have to use the variable 'payload', we can also just name it: 'item'
* @param {Object} item
*/
export function addToCart(item) {
return {
type: 'ADD',
item: item
};
}
export function removeFromCart(item) {
return {
type: 'REMOVE',
item: item
};
}
src/index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import registerServiceWorker from './registerServiceWorker';
import store from './store/index.js';
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>, document.getElementById('root'));
registerServiceWorker();
but i get the error TypeError: store.getState is not a function
. Can someone propose what steps should i look into first?
Looks like you forgot to create a store
object in index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import registerServiceWorker from './registerServiceWorker';
import Store from './store/index.js';
// forgot to create store obj
const store = Store();
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>, document.getElementById('root'));
registerServiceWorker();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With