Skip to content

Instantly share code, notes, and snippets.

@taggon
Forked from choipd/container.js
Last active November 21, 2017 06:42
Show Gist options
  • Save taggon/03d8cef3d35d0cc70b4a6067afefdf94 to your computer and use it in GitHub Desktop.
Save taggon/03d8cef3d35d0cc70b4a6067afefdf94 to your computer and use it in GitHub Desktop.
shouldComponentUpdate(nextProps, nextState){
console.log("component should update")
if(nextProps.status === POST_STATUS.POST_STATUS_SAVED) {
this._closePost()
}
return true
}
const mapStateToProps = (state, props) => {
const { status } = state.newPost
return {
...props,
state,
};
};
export const createPost = (postData) => {
return dispatch => {
const { currentUser } = firebase.auth()
firebase.auth().currentUser.getIdToken(false)
.then((idToken)=>{
console.log('token: ', idToken)
Axios.defaults.headers = {
'authorization': idToken,
'content-type': 'application/json'
}
const request = Axios.post(`https://.../createPost`, postData);
dispatch({
type: CREATE_POST,
})
return request;
})
.then(response => {
console.log('create post success', response)
dispatch({
type: CREATE_POST_SUCCESS,
});
})
.catch(error => {
console.log('error: ', error)
dispatch({
type: CREATE_POST_FAILED,
error,
})
})
}
}
case CREATE_POST_SUCCESS:
return {
...state,
status: POST_STATUS.POST_STATUS_SAVED,
};
case CREATE_POST_FAILED:
return {
...state,
status: POST_STATE.POST_STATUS_FAILED,
action.error,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment