reactjs - How to Access the State of the reducer in other reducer in reat redux -


i have login page component have state boolean called isuserauthenticated, when i'm clicking on login button checks userslist wheather user exists or not. users list in signupreducer, how can access users list in loginreducer , return isuserauthenticated flag it.

loginpage component

export const mapstatetoprops = (state) => {     return {         isuserauthenticated: state.reducer.isauthenticated.isuserauthenticated,         users: state.signupreducer.users     } }  export const mapdispatchtoprops = (dispatch) => {     return {         checklogin: (credentials) => dispatch({ type: 'check_login', credentials })     } };  loginpage = connect(mapstatetoprops, mapdispatchtoprops)(loginpage);  export default loginpage; 

login reducer

const initialstateauth = {     isuserauthenticated: false };  export const isauthenticated = (state = initialstateauth, action) => {     switch (action.type) {         case 'check_login':             return object.assign({}, state, { isuserauthenticated: checklogin(state, action) })         default:             return state;     } } 

here want check user in singupreducer.users how can access here....

const checklogin = (state, action) => {     let isexist = false;     signupreducer.users.map((each) => {         if (each.username === action.credentials.username && each.password === action.credentials.password) {             isexist = true;         }     });     return state.isuserauthenticated = false;  } 

i'm assuming you're using combinereducers set state tree. you'll need write custom combination function passes state need (from signup) login reducer.

there's example of how in redux docs: http://redux.js.org/docs/recipes/reducers/beyondcombinereducers.html#sharing-data-between-slice-reducers


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -