mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-02-08 22:48:36 -06:00
Created the ViewContext.jsx
This commit is contained in:
18
client/src/common/contexts/View/ViewContext.jsx
Normal file
18
client/src/common/contexts/View/ViewContext.jsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import React, {useState, createContext} from "react";
|
||||
|
||||
export const ViewContext = createContext({});
|
||||
|
||||
export const ViewProvider = (props) => {
|
||||
const [view, setView] = useState(parseInt(localStorage.getItem("view")) || 0);
|
||||
|
||||
const updateView = (newView) => {
|
||||
setView(newView);
|
||||
localStorage.setItem("view", newView);
|
||||
}
|
||||
|
||||
return (
|
||||
<ViewContext.Provider value={[view, updateView]}>
|
||||
{props.children}
|
||||
</ViewContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user