feat: Initialize project
This commit is contained in:
1 parent
eccc32337f
commit
3c1050898e
65 files changed
+5661
-596
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { createContext, Dispatch, ReactNode, SetStateAction, useEffect, useState } from 'react';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export const ThemeContext = createContext<[Theme, Dispatch<SetStateAction<Theme>>]>([
|
||||
Cookies.get('theme') as Theme,
|
||||
() => null
|
||||
]);
|
||||
|
||||
export default function Provider({ children, theme: initialTheme }: { children: ReactNode; theme?: Theme }) {
|
||||
const state = useState<Theme>((Cookies.get('theme') || initialTheme) as Theme);
|
||||
|
||||
const [theme, setTheme] = state;
|
||||
|
||||
useEffect(() => {
|
||||
if (!theme) {
|
||||
return setTheme(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
||||
}
|
||||
|
||||
document.documentElement.setAttribute('class', theme);
|
||||
Cookies.set('theme', theme);
|
||||
}, [theme, setTheme]);
|
||||
|
||||
return <ThemeContext.Provider value={state}>{children}</ThemeContext.Provider>;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
'use client';
|
||||
|
||||
import { ReactNode, useState } from 'react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental';
|
||||
|
||||
import ThemeProvider from '@/providers/Theme';
|
||||
|
||||
const Providers = ({ children, theme }: { children: ReactNode; theme?: Theme }) => {
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: Number.POSITIVE_INFINITY
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ReactQueryStreamedHydration>
|
||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||
</ReactQueryStreamedHydration>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Providers;
|
||||
Reference in new issue
Block a user