Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.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
Reactjs 如何在react js中实现JSX样式_Reactjs - Fatal编程技术网

Reactjs 如何在react js中实现JSX样式

Reactjs 如何在react js中实现JSX样式,reactjs,Reactjs,errorClr不工作。我正在将错误传递给它并声明 在渲染中,我 const { error }=this.state; const {errorClr}={style:{color : {error}}}; // this doesnt work the way? <div className="col-8" {...errorClr}>Please enter valid data</div> const{error}=this.state; const{err

errorClr不工作。我正在将错误传递给它并声明 在渲染中,我

const { error }=this.state;
const  {errorClr}={style:{color : {error}}}; // this doesnt work the way?

<div className="col-8" {...errorClr}>Please enter valid data</div>
const{error}=this.state;
const{errorClr}={style:{color:{error}}};//这样不行吗?
请输入有效数据
颜色属性不反映。我没有执行设置状态。我们不能做这种事吗{style:{color:{error}}}?另一条路是什么?
样式未被应用。

您应该这样编写样式:

const { error } = this.state;

<div className="col-8" style={{color:error}}>Please enter valid data</div>
const{error}=this.state;
请输入有效数据
使用

const  {errorClr}={style:{color : {error}}};
您正试图从对象
{style:{color:{error}}}
中解构
errorClr
,该对象显然不存在。你应该改为写信

const  errorClr = {style:{ color :  error }};

或者你可以简单地写

<div className="col-8" style={{color:error}}>Please enter valid data</div>
请输入有效数据

通过编写
const{errorClr}=
尝试从
{style:{color:{error}}
中解构
errorClr
属性。你想写
consterrorclr={style:{color:{error}}改为。@Thole不起作用:(不将颜色反映到文本上。您能解释一下-->const{errorClr}=您试图从{style:{color:{error}}中解构errorClr属性吗