Skip to content

Commit

Permalink
read theme mode from cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
2nthony committed Mar 26, 2024
1 parent a51706d commit fba4921
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions next/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import App from "next/app";
import Head from "next/head";
import { Provider } from "react-redux";
import NProgress from "nprogress";
Expand Down Expand Up @@ -43,7 +44,7 @@ const montserrat = Montserrat({
variable: "--font-montserrat",
});

function MyApp({ Component, pageProps }) {
function MyApp({ Component, pageProps, themeMode }) {
return (
<>
<style jsx global>{`
Expand All @@ -54,7 +55,7 @@ function MyApp({ Component, pageProps }) {
`}</style>

<Provider store={store}>
<ConfigProvider themeMode="system">
<ConfigProvider themeMode={themeMode}>
<Head>
<title>OpenSquare Network Off-chain Voting</title>
<meta
Expand All @@ -73,4 +74,16 @@ function MyApp({ Component, pageProps }) {
);
}

// https://nextjs.org/docs/pages/building-your-application/routing/custom-app#getinitialprops-with-app
MyApp.getInitialProps = async (context) => {
const ctx = await App.getInitialProps(context);

const themeMode = context.ctx.req?.cookies?.["theme-mode"];

return {
...ctx,
themeMode,
};
};

export default MyApp;

0 comments on commit fba4921

Please sign in to comment.