admin管理员组文章数量:1291013
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 IneList () {
return dispatch => {
return (
axios.post('http://139.196.141.166:8084/course/ine/outline',{}, {
headers: { 'X-Authenticated-Userid': '15000500000@1' }
}).then(function (response) {
dispatch(receiveData(response.data));
})
)
}
}
How it right way create reducer for that?
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 IneList () {
return dispatch => {
return (
axios.post('http://139.196.141.166:8084/course/ine/outline',{}, {
headers: { 'X-Authenticated-Userid': '15000500000@1' }
}).then(function (response) {
dispatch(receiveData(response.data));
})
)
}
}
How it right way create reducer for that?
Share Improve this question asked Jan 22, 2017 at 14:36 Егор КротенкоЕгор Кротенко 8183 gold badges14 silver badges35 bronze badges 2-
Did you export
listReducer
? – Giladd Commented Jan 22, 2017 at 14:43 - thanks... need export – Егор Кротенко Commented Jan 22, 2017 at 14:47
4 Answers
Reset to default 6Looks like you never exported your reducer. An export default listReducer
in your listReducer.js
file should do the trick.
- Store - holds our state - THERE IS ONLY ONE STATE
- Action - State can be modified using actions - SIMPLE OBJECTS
- Dispatcher - Action needs to be sent by someone - known as dispatching an action
- Reducer - receives the action and modifies the state to give us a new state
- pure functions
- only mandatory argument is the 'type'
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> ); } }
In my case I called the function immediately
const store = createStore(rootReducer())
instead of
const store = createStore(rootReducer)
It worked for me, Stop node (Ctrl + C) and restart it (npm start), reload the page (F5), you will see new results.
本文标签: javascriptreducer is not a functionStack Overflow
版权声明:本文标题:javascript - reducer is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521914a2383238.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论