2017-08-31 64 views
0

我製作了組件通知,我希望它的操作和縮減器可供所有應用程序使用。 但我不明白爲什麼我的行爲是說沒有定義。 這裏是表示定義爲什麼我的動作創作者沒有在react redux應用中定義?

import { SHOW_NOTIFICATION, SHOW_NOTIFICATION_FULFILLED } from 'constants/actionTypes' 

// notification 
const initialState = { 
    notification: {} 
} 

export function fetchNotification (data) { 
    return { 
    type: 'SHOW_NOTIFICATION', 
    data: data 
    } 
} 

export default function notificationReducer (state = initialState, action) { 
    switch (action.type) { 
    case SHOW_NOTIFICATION_FULFILLED: { 
     return { 
     ...state, 
     notification: action.data 
     } 
    } 
    } 
    return state 
} 

SHOW_FULFILLED的代碼,但從來沒有使用過有啥錯誤

+1

我認爲你是正確導入它們,在這裏:''常量/ actionTypes''它應該是用'啓動/常數/'或'../常數/' –

+0

不,我在導入它。正確的方式 –

回答

0

你叫行動SHOW_NOTIFICATION但減速只能SHOW_NOTIFICATION_FULFILLED處理。在減速器中使用與動作相同的動作類型。

// notification 
const initialState = { 
    notification: {} 
} 

export function fetchNotification (data) { 
    return { 
    type: 'SHOW_NOTIFICATION', // <-- 
    data: data 
    } 
} 

export default function notificationReducer (state = initialState, action) { 
    switch (action.type) { 
    case SHOW_NOTIFICATION: { // <-- 
     return { 
     ...state, 
     notification: action.data 
     } 
    } 
    } 
    return state 
} 
+0

不,我正在使用處理這種方式的承諾中間件 –

相關問題