Open mtr1990 opened 2 weeks ago
I have the same issue. Waiting for maintainer. Thanks
I have the same issue. Waiting for maintainer. Thanks
Same here!
The trick here is to use a type generic:
function Li({ children, ...other }: BoxProps<'li'>) {
function Ul({ children, ...other }: BoxProps<'ul'>) {
function Svg({ children, ...other }: BoxProps<'svg'>) {
See demo: typescript playground
This ensures that TypeScript understands what's going on, and also makes sure that you can, for example, pass the viewBox
prop to the Svg
component but not to the Li
and Ul
components.
The trick here is to use a type generic:
function Li({ children, ...other }: BoxProps<'li'>) { function Ul({ children, ...other }: BoxProps<'ul'>) { function Svg({ children, ...other }: BoxProps<'svg'>) {
See demo: typescript playground
This ensures that TypeScript understands what's going on, and also makes sure that you can, for example, pass the
viewBox
prop to theSvg
component but not to theLi
andUl
components.
This works perfectly for me, thank you!
Steps to reproduce
Based on the example provided from MUI https://github.com/mui/material-ui/tree/master/examples/material-ui-nextjs-ts
I have added the following code
I use this method in MUI v5 without any problems. However, the error appears in MUI v6. I read in the documentation that components were removed in MUI v6 https://github.com/mui/material-ui/releases/tag/v6.0.0-rc.0
But I still see the document is still in use: https://mui.com/material-ui/react-box/#basics
So the component in Box is actually removed?
Current behavior
Error message appears
Expected behavior
No TypeScript errors appeared.
I would like to understand clearly how to use Box in MUI v6.
Because in the project I use a lot of places like:
So it will take a lot of time to restructure the whole thing.
Looking forward to suitable suggestions for this situation. Thanks!