Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Last active January 26, 2024 03:16
Show Gist options
  • Select an option

  • Save PatrickJS/b378ccec43fa25d40b860f26bdfb0e2c to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/b378ccec43fa25d40b860f26bdfb0e2c to your computer and use it in GitHub Desktop.
qwik global app context
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