在使用material ui时,我意识到他们有一个名为in
的 Prop 在转换组件中,但是当尝试破坏 Prop 时,我不能,因为 in
是保留关键字。
const MyFade = ({ children, in, ...otherProps }) => { // this gives me an error
return (
<div {...otherProps}>
<Fade in={in}>{children}</Fade>
</div>
);
};
我该怎么做?我需要销毁in
并有otherProps
传播于div
.
最佳答案
只需在解构中分配一个新的、非保留的名称即可。
const o = {
in: 'foo',
out: 'boo',
};
const { in: inProp } = o;
// ^^^^ assign new name
console.log(inProp);
关于javascript - 名称为保留关键字的解构属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59219872/