Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3036 | Rev 3416 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3036 Rev 3407
Línea 1... Línea 1...
1
import { useState, useEffect } from 'react'
1
import { useState, useEffect } from 'react'
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from 'react-redux'
Línea 3... Línea 3...
3
 
3
 
4
import { axios } from '@utils'
4
import { axios } from '@utils'
5
import { logout } from '@store/auth/auth.actions'
5
import { asyncLogout } from '@store/auth/auth.actions'
Línea 6... Línea 6...
6
import { addNotification } from '@store/notification/notification.actions'
6
import { addNotification } from '@store/notification/notification.actions'
7
 
7
 
8
export function useFetch(url, defaultValue = {}) {
8
export function useFetch(url, defaultValue = {}) {
Línea 39... Línea 39...
39
      .get(url)
39
      .get(url)
40
      .then((response) => handleError(response))
40
      .then((response) => handleError(response))
41
      .then((data) => setData(data))
41
      .then((data) => setData(data))
42
      .catch((error) => {
42
      .catch((error) => {
43
        dispatch(addNotification({ style: 'danger', msg: error.message }))
43
        dispatch(addNotification({ style: 'danger', msg: error.message }))
44
        if (error.message.includes('sesión')) dispatch(logout())
44
        if (error.message.includes('sesión')) dispatch(asyncLogout())
45
      })
45
      })
46
      .finally(() => setIsLoading(false))
46
      .finally(() => setIsLoading(false))
47
  }
47
  }
Línea 48... Línea 48...
48
 
48