Skip to content

Instantly share code, notes, and snippets.

@choipd
Created November 21, 2017 06:29
Show Gist options
  • Save choipd/a2587fbd99aa27856706f8f1c59dd6e0 to your computer and use it in GitHub Desktop.
Save choipd/a2587fbd99aa27856706f8f1c59dd6e0 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,
payload: request
})
})
.catch(error => {
dispatch({
type: CREATE_POST_FAILED,
payload: error
})
})
}
}
case CREATE_POST: {
action.payload.then(
(response) => {
console.log('create post success', response)
return {
...state,
status: POST_STATUS.POST_STATUS_SAVED
}
})
.catch((error)=>{
console.log('error: ', error)
return {
...state,
status: POST_STATE.POST_STATUS_FAILED,
error
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment