Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: remove the unnecessary initial value of createContext in theme-provider #5000

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions apps/www/content/docs/dark-mode/vite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ type ThemeProviderState = {
setTheme: (theme: Theme) => void
}

const initialState: ThemeProviderState = {
theme: "system",
setTheme: () => null,
}

const ThemeProviderContext = createContext<ThemeProviderState>(initialState)
const ThemeProviderContext = createContext<ThemeProviderState | null>(null)

export function ThemeProvider({
children,
Expand Down Expand Up @@ -78,7 +73,7 @@ export function ThemeProvider({
export const useTheme = () => {
const context = useContext(ThemeProviderContext)

if (context === undefined)
if (!context)
throw new Error("useTheme must be used within a ThemeProvider")

return context
Expand Down