fabiobiondi

React Saga Example

Mar 21st, 2021 (edited)
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let callAPI = async ({ url, method, data }) => {
  2.   return await Axios({ url, method, data });
  3. };
  4.  
  5. export function* deleteItem({ id }) {
  6.   try {
  7.     const result = yield call(() =>
  8.       callAPI({ url: `${API}/items/${id}`, method: 'DELETE' })
  9.     );
  10.     yield put(deleteItemSuccess(result.data));
  11.   } catch (e) {
  12.     yield put(deleteItemFail());
  13.   }
  14. }
Add Comment
Please, Sign In to add comment