lundi 4 septembre 2017

React - Redux dispatch an action based on UI state

In my React component reducer state I have a selectedTabIndex property, specifying what tab is currently active in my UI.

const deviceRankReducer = (state = {
    selectedIndex:1
},action) ={
   //...
}

In my Redux action I want to make an AJAX call based on the selected tab index.

class MyActions extends ReduxActionsBase {
     sendRequest(){
          if(state.selectedIndex === 0){
             //make call to resource A
          }else{
             //make call to resource B
          }
     }
}

What is the best practice of sharing the information with the ReduxActionsBase without making an anti-pattern decision?

Aucun commentaire:

Enregistrer un commentaire