Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否使用“排列”操作符更改反应组件的样式?_Javascript_Css_Reactjs - Fatal编程技术网

Javascript 是否使用“排列”操作符更改反应组件的样式?

Javascript 是否使用“排列”操作符更改反应组件的样式?,javascript,css,reactjs,Javascript,Css,Reactjs,我试图使用spread操作符来影响React组件的样式,但它似乎不起作用 const newProps = { ...this.props, color: 'red' }; return ( <SU_Table.Cell {...newProps}> {this.props.children} </SU_Table.Cell> ); constnewprops={…this.props,颜色:'red'}; 返回( {this.props.childr

我试图使用spread操作符来影响React组件的样式,但它似乎不起作用

const newProps = { ...this.props, color: 'red' };

return (
  <SU_Table.Cell {...newProps}>
    {this.props.children}
  </SU_Table.Cell>
);
constnewprops={…this.props,颜色:'red'};
返回(
{this.props.children}
);

有人能告诉我是否可以用这种方式进行更改吗?

我真的不确定什么是
SU\u Table.Cell
。 但也许试试这个

const newProps = { ...this.props, color: 'red' };

return (
  <SU_Table.Cell styleProps={...newProps}>
    {this.props.children}
  </SU_Table.Cell>
);
如果您的
组件需要正常命名的道具(例如样式),那么这种方法应该可以工作。如果没有,您在控制台中是否收到任何错误消息

//假设“道具”是这样的
{
尺寸:12,
儿童:[],
一些相关信息:“@123Sadasd”,
文本:“单元格文本”
}
类表扩展组件{
渲染(){
//this.props的扩展将对对象应用不相关的属性
//const newProps={…this.props,样式:{color:'red'}
//传播this.props还会将“children”属性放入您的
//newProps对象,然后最终作为
//属性。
//只有从道具中得到你想要的东西才更简洁易读。
const{fontSize,text,children}=this.props
常量样式={fontSize,颜色:'red'}
const cellProps={text,style}
返回(
{儿童}
//
//  []
//
)
}

}
告诉我们这个.props里面有什么?是某个库中的
SU_Table.Cell
?也许你想把你的新对象命名为
样式
prop?我想知道当你放置一个console.log({props})时会发生什么;在SU_Table.Cell组件的render method()内部?是的,它是语义UI…好的,那么这个
SU_Table.Cell的API需要什么样的道具来设计自己?它还取决于
this.props
内部的道具,对吗?如果您有
this.props.fontSize=12子对象
),因为它已经被引用了两次(一次是在newProps的传播中,另一次是作为SU_Table.Cell的实际子对象),那么,你有什么建议呢?@jnoweb现在呢?
const SU_Table.Cell = (props) => {
     return (<div style={props.styleProps}> </div>)
}