MuiThemeProvider theme prop no longer accepts function in TypeScript
See original GitHub issueLooks like after the change as part of #9295 we can no longer pass a function to the MuiThemeProvider
component. An example of this can be seen in the docs at https://material-ui-next.com/customization/themes/#nesting-the-theme.
It worked before because of the generic used here:
export interface MuiThemeProviderProps {
theme?: Theme<any>;
...
Perhaps the prop should be a theme: Theme | (theme: Theme) => Theme
or something like that? Note the lack of the ?
on the item. The theme is marked as required by the component, so the interface should reflect that.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
MuiThemeProvider theme prop no longer accepts function in ...
Looks like after the change as part of #9295 we can no longer pass a function to the MuiThemeProvider component.
Read more >Property 'theme' does not exist when using typescript
For anyone running into a similar error message in 2020, my issue was that I was importing makeStyles from the @material-ui/styles package.
Read more >Theming - Material UI - MUI
Theming. Customize MUI with your theme. You can change the colors, the typography and much more. The theme specifies the color of the...
Read more >Function Components - React TypeScript Cheatsheets
Function Components. These can be written as normal functions that take a props argument and return a JSX element. // Declaring type of...
Read more >How to Setup React Testing Library for Material UI Styled ...
The function accepts ReactElement and returns a wrapped component with MuiThemeProvider and theme which is used in application root. And you can use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, looks like the increased type safety afforded by #9295 exposed a bug in the typing of
MuiThemeProviderProps
. Would you care to open a PR for this?For anyone stumbling here with an error like the following (because the above discussion has similar typings mentioned and make this result pop up on Google searches),
see https://github.com/mui-org/material-ui/issues/14431#issuecomment-494536911