【发布时间】:2021-11-26 03:11:31
【问题描述】:
我看到以下示例 JSX 代码:
const AppBar = styled(MuiAppBar, {
shouldForwardProp: (prop) => prop !== 'open',
})<AppBarProps>(({ theme, open }) => ({
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
...(open && {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
}),
}));
我不明白在做什么。
所以我用babel翻译得到:
const AppBar = styled(MuiAppBar, {
shouldForwardProp: prop => prop !== 'open'
}) < AppBarProps > (({
theme,
open
}) => ({
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen
}),
...(open && {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen
})
})
}));
这是什么...< AppBarProps >...是什么意思? (其余的我理解就好了)
抱歉,这似乎是有史以来最愚蠢的问题,但无法想象这里发生了什么。
【问题讨论】:
-
您实际拥有的是 TSX,而不是 JSX。这是打字稿。
标签: javascript material-ui jsx