Skip to content

Instantly share code, notes, and snippets.

@n4bb12
Created January 28, 2023 08:15
Show Gist options
  • Save n4bb12/186b317529150e875c6ddfdf0277f795 to your computer and use it in GitHub Desktop.
Save n4bb12/186b317529150e875c6ddfdf0277f795 to your computer and use it in GitHub Desktop.
Next.js PageProps Context
import { createContext, useContext } from "react"
import { RootLayoutData } from "src/data/types"
export const pagePropsContext = createContext({})
export const PagePropsProvider = pagePropsContext.Provider
export function usePageProps<T>() {
return useContext<T & RootLayoutData>(pagePropsContext as any)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment