Skip to content

Instantly share code, notes, and snippets.

@tpai
Created October 16, 2018 04:09
Show Gist options
  • Select an option

  • Save tpai/90507255db14ae777fb3c9e3a4e2ebe1 to your computer and use it in GitHub Desktop.

Select an option

Save tpai/90507255db14ae777fb3c9e3a4e2ebe1 to your computer and use it in GitHub Desktop.
const updateTitle = title => {
return async dispatch => {
dispatch({ type: UPDATE_TITLE });
try {
const res = await fetch(url, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: { title }
});
const json = await res.json();
dispatch({ type: UPDATE_TITLE_SUCCESS, data: json });
} catch(err) {
dispatch({ type: UPDATE_TITLE_FAILED });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment