-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs): add global context for os toggle state (#1116)
- Loading branch information
1 parent
9b0b0c1
commit 23e3637
Showing
4 changed files
with
62 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { createContext, useContext, useEffect, useState } from "react"; | ||
|
||
const OSContext = createContext<{ | ||
selectedOS: string; | ||
setSelectedOS: (os: string) => void; | ||
}>({ | ||
selectedOS: "windows", | ||
setSelectedOS: () => {}, | ||
}); | ||
|
||
export const OSProvider: React.FC<{ children: React.ReactNode }> = ({ | ||
children, | ||
}) => { | ||
const [selectedOS, setSelectedOS] = useState<string>("windows"); | ||
|
||
useEffect(() => { | ||
const osString = localStorage.getItem("storedOsOption") || "windows"; | ||
setSelectedOS(osString); | ||
}, []); | ||
|
||
return ( | ||
<OSContext.Provider value={{ selectedOS, setSelectedOS }}> | ||
{children} | ||
</OSContext.Provider> | ||
); | ||
}; | ||
|
||
export const useOSContext = () => useContext(OSContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters