Adding UI Context

This commit is contained in:
Belen Curcio
2020-09-30 15:56:32 -03:00
parent 3dc2c16cea
commit 1af9a980df
6 changed files with 40 additions and 28 deletions

View File

@@ -1,15 +1,16 @@
import React, { Context, FunctionComponent } from "react";
export interface ContextType {
displaySidebar: boolean;
}
const initialState = {
displaySidebar: false,
dispatch: null,
};
export interface UIState {
displaySidebar: boolean;
dispatch: (string) => void;
}
function uiReducer(state, action) {
switch (action.type) {
switch (action) {
case "OPEN_SIDEBAR": {
return {
...state,
@@ -19,13 +20,13 @@ function uiReducer(state, action) {
case "CLOSE_SIDEBAR": {
return {
...state,
displaySidebar: true,
displaySidebar: false,
};
}
}
}
export const UIContext = React.createContext<ContextType>(initialState);
export const UIContext = React.createContext<UIState>(initialState);
UIContext.displayName = "UIContext";
export const UIProvider: FunctionComponent = (props) => {