Last active
January 26, 2024 03:16
-
-
Save PatrickJS/b378ccec43fa25d40b860f26bdfb0e2c to your computer and use it in GitHub Desktop.
qwik global app context
This file contains hidden or 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
| import { | |
| Slot, | |
| component$, | |
| createContextId, | |
| useContextProvider, | |
| useSignal, | |
| useStore, | |
| type Signal, | |
| } from '@builder.io/qwik'; | |
| export interface AppStore { | |
| themeModal: Signal<boolean>; | |
| showThemes: Signal<boolean>; | |
| contactModal: Signal<boolean>; | |
| organization: Signal<string>; | |
| currentDate: Signal<string>; | |
| } | |
| export const AppContext = createContextId<AppStore>('app-context'); | |
| export const AppProvider = component$(() => { | |
| const showThemes = useSignal(false); | |
| const themeModal = useSignal(false); | |
| const organization = useSignal(''); | |
| const currentDate = useSignal(new Date().toDateString()); | |
| const contactModal = useSignal(false); | |
| const app = useStore({ | |
| themeModal, | |
| contactModal, | |
| showThemes, | |
| organization, | |
| currentDate, | |
| }); | |
| useContextProvider(AppContext, app); | |
| return <Slot />; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment