Skip to content

Instantly share code, notes, and snippets.

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

  • Save tpai/6f4c2844d05258d0eed55c592e054fbe to your computer and use it in GitHub Desktop.

Select an option

Save tpai/6f4c2844d05258d0eed55c592e054fbe to your computer and use it in GitHub Desktop.
const updateTitleAPI = fetch(url, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: { title }
}).then(res => res.json());
const updateTitle = title => ({ type: UPDATE_TITLE, payload: title });
function* updateTitle({ payload }) {
try {
const json = yield call(updateTitleAPI, payload.title);
yield put({ type: UPDATE_TITLE_SUCCESS, data: json });
yield fork(fetchArticles);
} catch(err) {
yield put({ type: UPDATE_TITLE_FAILED });
}
}
function* watchUpdateTitle() {
yield takeLatest(UPDATE_TITLE, updateTitle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment