@magicbell/react-headless
Version:
Hooks to build a notification inbox
24 lines • 697 B
JavaScript
import { create } from 'zustand';
import ConfigRepository from './ConfigRepository.js';
/**
* Remote configuration store. It contains all settings stored in MagicBell
* servers for this user.
*
* @example
* const { fetch } = useConfig();
* useEffect(() => fetch(), []);
*/
const useConfig = create((set, get) => ({
channels: undefined,
inbox: undefined,
ws: undefined,
lastFetchedAt: undefined,
_repository: new ConfigRepository(),
fetch: async () => {
const { _repository } = get();
const json = await _repository.get();
set({ ...json, lastFetchedAt: Date.now() });
},
}));
export default useConfig;
//# sourceMappingURL=useConfig.js.map