Shell_Casing

context.js - TypeError: checkAuthStatus is not a function

Aug 4th, 2020
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useEffect, useReducer, createContext } from 'react';
  2. import axios from 'axios';
  3. import { Reducer } from "./reducer";
  4. import { SET_LOADING, SET_USER_DATA } from "../types";
  5. import { config } from "../../config/axios";
  6.  
  7. const { httpHeaders, AUTH_URL, authAxios } = config;
  8.  
  9. const InitialState = {
  10.     loading: false,
  11.     userData: {},
  12.     isAuthenticated: false
  13. };
  14.  
  15. export const AuthContext = createContext(InitialState);
  16.  
  17. export const AuthState = ({ children }) => {
  18.  
  19.     const [state, dispatch] = useReducer(Reducer, InitialState);
  20.  
  21.     const setLoading = () => dispatch({ type: SET_LOADING });
  22.  
  23.     const checkAuthStatus = async () => {
  24.         const { data } = await authAxios.post('/auth', null, httpHeaders);
  25.         console.log(data);
  26.     };
  27.  
  28.     const setUserData = (data) => dispatch({ type: SET_USER_DATA, payload: data });
  29.  
  30.     return (
  31.         <AuthContext.Provider value={{
  32.             loading: state.loading,
  33.             isAuthenticated: state.isAuthenticated,
  34.             userData: state.userData,
  35.             setLoading,
  36.             checkAuthStatus,
  37.             setUserData
  38.         }}>
  39.             { children }
  40.         </AuthContext.Provider>
  41.     )
  42.  
  43. };
  44.  
  45.  
Add Comment
Please, Sign In to add comment