Skip to content

Instantly share code, notes, and snippets.

@JaosnHsieh
Last active April 19, 2018 02:12
Show Gist options
  • Save JaosnHsieh/d0ab94ef6c8a87f4a3ba33b350ddb642 to your computer and use it in GitHub Desktop.
Save JaosnHsieh/d0ab94ef6c8a87f4a3ba33b350ddb642 to your computer and use it in GitHub Desktop.
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);
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"
};
};
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