mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 15:28:47 +00:00
add global settings context
will be useful going forward, and simplify widget props being passed around all over the place
This commit is contained in:
parent
244a76de0b
commit
a677fbefbf
9 changed files with 57 additions and 28 deletions
15
src/utils/settings-context.jsx
Normal file
15
src/utils/settings-context.jsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { createContext, useState, useMemo } from "react";
|
||||
|
||||
export const SettingsContext = createContext();
|
||||
|
||||
export function SettingsProvider({ initialSettings, children }) {
|
||||
const [settings, setSettings] = useState({});
|
||||
|
||||
if (initialSettings) {
|
||||
setSettings(initialSettings);
|
||||
}
|
||||
|
||||
const value = useMemo(() => ({ settings, setSettings }), [settings]);
|
||||
|
||||
return <SettingsContext.Provider value={value}>{children}</SettingsContext.Provider>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue