Reputation: 818
Try create reducers ang get data from action
But get error in console: reducer is not a function.....
My reducer:
import { INCOME_LIST } from '../actionTypes'
import Immutable from 'immutable'
const initialUserState = {
list: []
}
const listReducer = function(state = initialUserState, action) {
switch(action.type) {
case 'INCOME_LIST':
return Object.assign({}, state, { list: action.data });
}
return state;
}
Where I have mistake?
My Action :
import axios from 'axios'
import { INCOME_LIST } from '../actionTypes'
function receiveData(json) {
return{
type: INCOME_LIST,
data: json
}
};
export function IncomeList () {
return dispatch => {
return (
axios.post('http://139.196.141.166:8084/course/income/outline',{}, {
headers: { 'X-Authenticated-Userid': '15000500000@1' }
}).then(function (response) {
dispatch(receiveData(response.data));
})
)
}
}
How it right way create reducer for that?
Upvotes: 3
Views: 12286
Reputation: 1
It worked for me, Stop node (Ctrl + C) and restart it (npm start), reload the page (F5), you will see new results.
Upvotes: 0
Reputation: 1603
In my case I called the function immediately
const store = createStore(rootReducer())
instead of
const store = createStore(rootReducer)
Upvotes: 0
Reputation: 203
Subscriber - listens for state change to update the ui
const initialState = {
counter: 0
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'INCREASE_COUNTER':
return { counter: state.counter + 1 }
case 'DECREASE_COUNTER':
return { counter: state.counter - 1 }
}
return state
}
const store = createStore(reducer)
class App extends Component {
render() {
return (
<Provider store={store}>
<CounterApp />
</Provider>
);
}
}
Upvotes: 0
Reputation: 2290
Looks like you never exported your reducer. An export default listReducer
in your listReducer.js
file should do the trick.
Upvotes: 6