Last active
September 6, 2018 20:53
-
-
Save thesabbir/4d4228c9c6fd7b415fd52d4f19f2323f to your computer and use it in GitHub Desktop.
Redux with example: Share state between two reducers https://thesabbir.com/redux-with-example-share-state-between-two-reducers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using redux thunk async action | |
export function initiateNewChat(id, message) { | |
return (dispatch, getState) => { | |
// get friend from friends store | |
const friend = getState() | |
.friends[id]; | |
if (friend) { | |
// if friend exists we initiate new chat | |
return { | |
type: 'INITIATE_CHAT', | |
friend, | |
message | |
}; | |
} | |
// if not we return a error action | |
return { | |
type: 'ERROR_CREATING_CHATBOX', | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// state = chatoboxes | |
export function chatBoxReducer(state = {}, action) { | |
switch (action.type) { | |
case 'INITIATE_CHAT': | |
// We have friends data with action.friend | |
return state; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment