Created the SettingsProvider.jsx
This commit is contained in:
18
client/src/common/contexts/SettingsProvider.jsx
Normal file
18
client/src/common/contexts/SettingsProvider.jsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import {createContext, useState} from "react";
|
||||||
|
|
||||||
|
export const SettingsContext = createContext({});
|
||||||
|
|
||||||
|
export const SettingsProvider = ({children}) => {
|
||||||
|
const [rounds, setRounds] = useState(localStorage.getItem("rounds") || 10);
|
||||||
|
|
||||||
|
const updateRounds = (newValue) => {
|
||||||
|
localStorage.setItem("rounds", newValue);
|
||||||
|
setRounds(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SettingsContext.Provider value={{rounds, updateRounds}}>
|
||||||
|
{children}
|
||||||
|
</SettingsContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user