Guest User

21_xD-37

a guest
Jan 10th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import axios from 'axios';
  2. import { useDispatch } from 'react-redux';
  3.  
  4. class Request() {
  5.  
  6.     constructor(){
  7.         this.init()
  8.     }
  9.  
  10.     init(){
  11.         axios.interceptors.response.use({ data, status }) => {
  12.             if(status === 204){
  13.                 const dispatch = useDispatch();
  14.                 dispatch({type: 'SOMETHING_CREATED', alert: 'Created');
  15.             }
  16.         },
  17.         ({ error }) => {
  18.             const dispatch = useDispatch();
  19.             dispatch({type: 'SOMETHING_WRONG', alert: 'Not created');
  20.         })
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment