Reputation: 147
Given that in a file called goose.js I have exported a reducer as such:
//reducer
const reducer = handleActions(
{
[setExchangeRate]: (state, { exchangeRate }) => ({
...state,
exchangeRate
}),
[setExchangeCurrency]: (state, { exchangeCurrency }) => ({
...state,
exchangeCurrency
}),
[setBaseCurrency]: (state, { baseCurrency }) => ({
...state,
baseCurrency
})
},
initialState
);
export default reducer;
const selectCurrencyExchange = state => state[MODULE_NAME];
and in another file called index.jas, I try to import the reducer and assigned it to a provider:
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import reducer from "./redux/goose";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(
<Provider store={reducer}>
<App />
</Provider>,
rootElement
);
is there a reason why I am getting TypeError store.getState is not a function error? Is it illegal to do this?
The dependencies I am using is react 16.8.2, react-redux 5.07, redux, redux actions, redux-define.
I welcome an example that allows me to use the reducer structure in goose.js
Upvotes: 1
Views: 35
Reputation: 1877
react-redux Provider
is taking a store not a reducer.
You need to create the store with use of createStore
function from redux library and pass to it your reducer. And after that you can pass the created store to the Provider
.
Have a look at the basic example in redux documentation.
Upvotes: 1