i am using next js in my project and when i create a button to change colour they only change the base web components colour not background colour.
_app.tsx
import '../styles/globals.css';
import type { AppProps } from 'next/app';
import { Provider as StyletronProvider } from 'styletron-react';
import { LightTheme, BaseProvider, ThemeProvider, DarkTheme } from 'baseui';
import { styletron } from '../helpers/styletron';
import { useState } from 'react';
const THEME = {
light: 'light',
dark: 'dark',
};
function MyApp({ Component, pageProps }: AppProps) {
const [theme, setTheme] = useState(THEME.light);
return (
<StyletronProvider value={styletron}>
<BaseProvider
theme={theme === THEME.light ? LightTheme : DarkTheme}
>
<Component
{...pageProps}
THEMES={THEME}
theme={theme}
settheme={setTheme}
/>
</BaseProvider>
</StyletronProvider>
);
}
export default MyApp;
index.tsx
import type { NextPage } from 'next';
import Navbar from '../components/Navbar';
interface props {
THEMES: {
light: string;
dark: string;
};
settheme: any;
theme: any;
}
const Home: NextPage<props> = ({ THEMES, settheme, theme }) => {
return (
<>
<Navbar />
<button
onClick={() =>
settheme(theme === THEMES.dark ? THEMES.light : THEMES.dark)
}
>
change
</button>
</>
);
};
export default Home;
and when i click on button it not change the background colour to black
like you see above it not change the background
don't known it's the best way of doing it but it's work
what i do is add a class in html tag called theme which indicate the current theme which user select and store that theme name in localstorage and using css to add background colour according to html class name
if anyone has better solution pls don't hesitate to share.
_app.tsx
_document.tsx
index.tsx
globals.css