Skip to content

Commit

Permalink
'children' is missing in props validation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanLimaAngelo committed Oct 14, 2024
1 parent 504aad0 commit e484c3a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions frontend/src/context/DarkMode/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { createContext, useState, useContext } from "react";
import React, { createContext, useState, useContext, useMemo } from "react";
import PropTypes from "prop-types";
import { createMuiTheme, ThemeProvider as MUIThemeProvider } from "@material-ui/core/styles";
import { CssBaseline } from "@material-ui/core";

Expand All @@ -11,20 +12,29 @@ export const ThemeProvider = ({ children }) => {
setDarkMode((prevMode) => !prevMode);
};

const theme = createMuiTheme({
palette: {
type: darkMode ? "dark" : "light",
},
});
const theme = useMemo(
() =>
createMuiTheme({
palette: {
type: darkMode ? "dark" : "light",
},
}),
[darkMode]
);

const contextValue = useMemo(() => ({ darkMode, toggleTheme }), [darkMode]);

return (
<ThemeContext.Provider value={{ darkMode, toggleTheme }}>
<ThemeContext.Provider value={contextValue}>
<MUIThemeProvider theme={theme}>
<CssBaseline />
{children}
</MUIThemeProvider>
</ThemeContext.Provider>
);
};
ThemeProvider.propTypes = {
children: PropTypes.node.isRequired,
};

export const useThemeContext = () => useContext(ThemeContext);

0 comments on commit e484c3a

Please sign in to comment.