Skip to content

Instantly share code, notes, and snippets.

@yaodong
Created July 20, 2019 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaodong/6e00d7d15a2a316d26ad1ff7a8b18f94 to your computer and use it in GitHub Desktop.
Save yaodong/6e00d7d15a2a316d26ad1ff7a8b18f94 to your computer and use it in GitHub Desktop.
a.js
const mapDispatchToProps = (dispatch) => {
create: function(name) {
dispatch(createUser(name));
dispatch(displayUser(name));
}
}
connect(mapDispatchToProps)(A)
--------------------------------------------------
action.js
function createUserSuccess(name) {
return {type: "CREAT_URSER_OK", name: name};
}
function createUserError(error) {
return {type: "CREAT_URSER_ERROR", error: error};
}
function createUser(name) {
return function(dispatch) {
fetch(url).then((name) => {
dispatch(createUserSuccess(name));
})
.catch((error) => {
dispatch(createUserError(error));
})
}
}
function displayUser(name) {
return function(dispatch) {
validate()
.then(() => dispatch({type: "DISPLAY_USER", name: name}))
}
}
--------------------------------------------------------
b.js
const mapDispatchToProps = (dispatch) => {
create: function(name) {
dispatch(createUser(name));
dispatch(displayUser(name));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment