pcm-shared-components 2.1.108 → 2.1.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,23 @@
1
- import React, { ReactNode } from "react";
1
+ import React, { useMemo } from "react";
2
2
  import { createTheme, useTheme, ThemeProvider } from "@mui/material/styles";
3
3
 
4
4
  /**
5
- * Used to bridge the gab between MUI4 currently used in the app and MUI5 used in this library.
6
- * By wrapping the app with this function allows the MUI5 theme provider to properly receive the theme eliminating the need to pass in the theme manually as a props to each component.
7
- *
5
+ * Used to bridge the gap between MUI4 currently used in the app and MUI5 used in this library.
6
+ * Wrapping the app with this component makes the MUI5 ThemeProvider inherit the existing theme.
8
7
  */
9
8
  export const PcSharedComponentThemeInheritor = props => {
10
9
  const {
11
10
  theme,
12
- children = ReactNode
11
+ children
13
12
  } = props;
14
- const currentTheme = createTheme(theme ? theme : useTheme());
13
+
14
+ // MUI5 theme from the parent (MUI4 theme adapter or MUI5 provider)
15
+ const outerTheme = useTheme();
16
+
17
+ // Build final theme once per change
18
+ const mergedTheme = useMemo(() => createTheme(theme || outerTheme), [theme, outerTheme]);
15
19
  return /*#__PURE__*/React.createElement(ThemeProvider, {
16
- theme: theme
20
+ theme: mergedTheme
17
21
  }, children);
18
22
  };
19
23
  export default PcSharedComponentThemeInheritor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pcm-shared-components",
3
- "version": "2.1.108",
3
+ "version": "2.1.109",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "babel": {