Skip to content

Commit

Permalink
add useMemo to ThemeProvider theme
Browse files Browse the repository at this point in the history
  • Loading branch information
lappi-lynx committed Apr 11, 2024
1 parent deba19b commit 46467c0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/infrastructure/providers/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { ThemeProvider as MUIThemeProvider } from '@mui/material/styles';
import { createTheme, PaletteMode } from "@mui/material";
Expand All @@ -13,10 +13,11 @@ export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ childre
const searchParams = new URLSearchParams(location.search);
const getThemeMode = (themeParam: string | null) => themeParam === Themes.Light ? Themes.Light : Themes.Dark;
const mode: PaletteMode = getThemeMode(searchParams.get('theme'));
const themeInit = (mode: PaletteMode) => createTheme({

const theme = useMemo(() => createTheme({
palette: {
mode: mode,
...(mode === 'light' ? {
...(mode === Themes.Light ? {
background: {
default: '#EEEEEE',
paper: '#EEEEEE',
Expand Down Expand Up @@ -62,10 +63,10 @@ export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ childre
},
})
},
});
}), [mode]);

return (
<MUIThemeProvider theme={themeInit(mode)}>
<MUIThemeProvider theme={theme}>
{children}
</MUIThemeProvider>
);
Expand Down

0 comments on commit 46467c0

Please sign in to comment.