Stupid basic auth

This commit is contained in:
Daniel Cortes
2020-06-23 02:07:01 -04:00
parent 504a37545d
commit db3d0ce4d3
3 changed files with 69 additions and 23 deletions

View File

@@ -1,11 +1,34 @@
import React, {createContext, useContext, useReducer} from 'react';
const initialState = {user: {auth: false}};
const reducer = (state, action) => {
console.log(state, action);
switch (action.type) {
case 'login':
return {
...state,
user: action.user
}
case 'logout':
return {
...state,
user: action.user
}
default: return state;
}
};
export const StateContext = createContext(null);
export const StateProvider = ({reducer, initialState, children}) => (
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
);
export const StateProvider = ({children}) => {
return (
<StateContext.Provider value={useReducer(reducer, initialState )}>
{children}
</StateContext.Provider>
);
}
export const useStateValue = () => useContext(StateContext);