我有一个这样的类对象:
classes: {
divBlock: "divBlockClass",
rootBlock: "rootBlockClass"
}
如何获取divBlock属性并将其传递给otherProps剩余的类对象
const Component = ({height, className, classes /*i need to take a divBlock property*/, ...otherProps}) => {
console.log(otherProps); //log props who are not pulled out
return (
<div>
</div>
)
};
答案 0 :(得分:1)
您可以在函数主体中传播props
。
const Component = (props) => {
const {height, className, classes, ...restProps} = props;
const { divBlock, ...restClassProps } = classes;
const otherProps = {...restProps, classes: restClassProps };
console.log(otherProps); //log props who are not pulled out
return <div />
};
答案 1 :(得分:0)
这样做:
const Component = ({
height,
className,
classes : { divBlock }, ...otherProps
}) => {
console.log(otherProps);
return (
<div>
</div>
)
};