Last active
April 19, 2018 02:12
-
-
Save JaosnHsieh/d0ab94ef6c8a87f4a3ba33b350ddb642 to your computer and use it in GitHub Desktop.
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
import * as actions from "./actions.js"; | |
const mapStateToProps = (state, ownProps) => ({ | |
test: state.test, | |
result: state.result, | |
loading: state.loading | |
}); | |
const mapDispatchToProps = (dispatch, ownProps) => ({ | |
addOne: () => { | |
dispatch(actions.addOne()); | |
}, | |
getAsyncValue: () => { | |
dispatch(actions.fetchJsonApi()); | |
} | |
}); | |
export default connect(mapStateToProps, mapDispatchToProps)(Chat); |
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
export const fetchJsonApi = () => { | |
return (dispatch, getState) => { | |
dispatch({ | |
type: "START_LOADING" | |
}); | |
return fetch("https://jsonplaceholder.typicode.com/posts/1") | |
.then(response => response.json()) | |
.then(json => | |
dispatch({ | |
type: "GOT_RESULT", | |
result: json.title | |
}) | |
); | |
}; | |
}; | |
export const addOne = () => { | |
return { | |
type: "ADD_TEST" | |
}; | |
}; |
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
import * as actions from "./actions.js"; | |
const mapStateToProps = (state, ownProps) => ({ | |
test: state.test, | |
result: state.result, | |
loading: state.loading | |
}); | |
export default connect(mapStateToProps, { | |
addOne: actions.addOne, | |
getAsyncValue: actions.fetchJsonApi | |
})(Chat); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment