migrated to vite and vite-plugin-ssr
This commit is contained in:
22
src/utils/hooks/usePageContext.tsx
Normal file
22
src/utils/hooks/usePageContext.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
// `usePageContext` allows us to access `pageContext` in any React component.
|
||||
// See https://vite-plugin-ssr.com/pageContext-anywhere
|
||||
import type { PageContext } from '@renderer/types';
|
||||
|
||||
import { createContext, useContext } from 'react';
|
||||
|
||||
const Context = createContext<PageContext>(undefined as any);
|
||||
|
||||
export function PageContextProvider({
|
||||
pageContext,
|
||||
children,
|
||||
}: {
|
||||
pageContext: PageContext;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return <Context.Provider value={pageContext}>{children}</Context.Provider>;
|
||||
}
|
||||
|
||||
export function usePageContext() {
|
||||
const pageContext = useContext(Context);
|
||||
return pageContext;
|
||||
}
|
||||
Reference in New Issue
Block a user