Closed dBitech closed 1 year ago
Hi @dBitech thank you for the contributions.
I have taken a look at PR #131 and it looks like a useful feature/addition. Does this resolve the issue raised here or do you want us to look into the problem together. In the latter case please add the full error message and steps on how to reproduce it.
If you add your custom ThemeProvider below MapComponentsProvider, then this error should not be thrown. The theme prop of the custom theme should be provided as a function that has the current theme defined up in the React DOM as a parameter and returns the new theme:
<MapComponentsProvider>
<ThemeProvider theme={outerTheme => ({...outerTheme, ...customTheme })}>
<App />
</ThemeProvider>
</MapComponentsProvider>
https://mui.com/system/styles/advanced/#theme-nesting
We need to be careful that the spread operator will not merge but replace object values. So in some case a more sophisticated merge-themes function might be required.
I will address the need for better/any documentation on theming in our next project meeting.
Edit: PR #131 is now also merged and will be in the next release. I'll keep this issue open for further discussion on the theming issue.
Yes, this looks to have solved the immediate issue thank you. I'm rather new to react, the theme switching was based on code copied out of the powerplant App from react-map-components-apps since I could not find any other meaningful documentation or examples.
I just had to fix a similar issue in one of our apps.
To make sure the higher level props don't overwrite each other @mui/utils exports the function deepmerge. In your case you could use it as follows:
import { deepmerge } from '@mui/utils';
<MapComponentsProvider>
<ThemeProvider theme={outerTheme => deepmerge(outerTheme, customTheme )}>
<App />
</ThemeProvider>
</MapComponentsProvider>
Just released v0.1.86 that includes your changes.
When attempting to use dark mode via theme switcher, the following error is thrown:
PR #131 attempts to resolve this