I'm trying to detect URL path inside my nextjs app and set the initial state based on the url path in the context
, but am getting window is not defined. I know window
won't be defined until client render but where would i put it if I want to pass initial state into context?
import React, {createContext, useReducer} from "react";
import Reducer from './reducer'
const initialState = {
'about': window.location.pathname == 'about' ? true : false
};
const Store = ({children}) => {
const [state, dispatch] = useReducer(Reducer, initialState);
return (
<Context.Provider value={[state, dispatch]}>
{children}
</Context.Provider>
)
};
export const Context = createContext(initialState);
export default Store;