2017-11-07 10 views
0

を解雇:リターン(派遣)ではない私はReduxので初心者です、これは私のコードである

コンポーネント:alerteProduit.js

// Map Redux state to component props 
function mapStateToProps(state) { 
    return { 
    alertes: state.dashboardDomain.Qualite, //récupération de la liste contenu dans le state (dashboard_reducer -> Qualite) 
    } 
} 

// Map Redux actions to component props 
function mapDispatchToProps(dispatch) { 
    return { 
    getAlertes:() => dashboard_actions.dashboard_getAlerteProduit(), //appel méthode action vers api 
    } 
} 

export default connect(mapStateToProps, mapDispatchToProps)(AlerteProduit); 

dashboard_action.js

export function dashboard_getAlerteProduit() { 
    console.log("fired") 
    return (dispatch) => { 
    console.log("not fired") 
    var alertes = Deserialize(storage.get("alertes")) 

    if (!alertes) {//si pas d'alertes dans le store local on va les chercher dans l'api 
     dashboard_api.getAlerteProduits(dispatch, storage.get("1483")) //la fonction getAlerteProduits() attend l'id du client connecté 
     .then((ap) => { 
      storage.set("alertes", Serialize(ap)) 
      dispatch(Get_AlerteProduits(ap)) 
     }) 
    } else {//si on a déjà des alertes dans le store local on les renvois 
     dispatch(Get_AlerteProduits(alertes)) 
    } 
    }; 
} 

dashboard_api.js

export function getAlerteProduits(dispatch, idClient) { 
    return auth_get_dispatch(dispatch, '/api/Produits/GetRappelProduit?idClient=' + idClient) 
} 

dashboard_action.jsには、メソッドの開始部分が呼び出されますが、「戻る」の後には表示されません。私のプロジェクトで何が間違っているか知っていますか?ところで、私のAPIが正しい結果を返しているので、エラーはこの側からではありません。

+0

あなたが持つオブジェクトを返すされています。また

、あなたがdashboard_getAlerteProduitで矢印関数内の復帰を必要とします"タイプ"キー? – EnriqueDev

答えて

1

私はあなたのエラーがmapDispatchToPropsにあると思います。

getAlertes:() => dashboard_actions.dashboard_getAlerteProduit() 

それは次のようになります。

getAlertes:() => dispatch(dashboard_actions.dashboard_getAlerteProduit()) 

を更新:

if (!alertes) {//si pas d'alertes dans le store local on va les chercher dans l'api 
    return dashboard_api.getAlerteProduits(dispatch, storage.get("1483")) //la fonction getAlerteProduits() attend l'id du client connecté 
    .then((ap) => { 
     storage.set("alertes", Serialize(ap)) 
     dispatch(Get_AlerteProduits(ap)) 
    }) 
} else {//si on a déjà des alertes dans le store local on les renvois 
    return dispatch(Get_AlerteProduits(alertes)) 
} 
+0

それでもうまくいきません。 – Phobie

+0

@Phobie答えを更新しました。 –

関連する問題