Hey, I'm trying to deploy a site with gatsby but I'm getting an error
firedev99
Posted on May 13, 2020
so I'm getting an error saying cannot destructure property 'currentTheme' object as it is undefined
//Layout
const {currentTheme, cursorStyles} = useGlobalStateContext()
const dispatch = useGlobalDispatchContext()
//GlobalContext
const globalReducer = (state, action) => {
switch(action.type) {
case "TOGGLE_THEME": {
return {
...state,
currentTheme: action.theme,
}
}
case "CURSOR_TYPE": {
return {
...state,
cursorType: action.cursorType,
}
}
default : {
throw new Error(unhandled action type: ${action.type}
)
}
}
}
//Provider
export const GlobalProvider = ({children}) => {
const [state, dispatch] = useReducer(globalReducer, {
currentTheme: window.localStorage.getItem("theme") === null ? "dark" : window.localStorage.getItem("theme"),
cursorType: false,
cursorStyles: ["pointer", "hovered", "nav-open"]
})
Posted on May 13, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.