我初学React,懵懵懂懂,我把基础的html语法直接搬到JSX文件中,React提示我:
Line 17:36: Style prop value must be an object react/style-prop-object
我写的是:
class CYXQHome extends React.Component {
render(){
return (
<div id="showDiv1" style="display:none;position:relative;left:69px;width:360px" />
);
}
}
出现这种错误的原因是 style=xxxx 那部分,style必须是一个对象 。修改后
<div id="showDiv1" style={ { display:"none",position:"relative",left:"69px",width:"360px" } } />
如上,有两个花括号, {{ {} }},外部的 { {} } 表示这是Javascript句法,里面的 { {} } 是一个对象。