即使我已应用propType验证,但在传递hasvacancy
prop的布尔值时,我的编辑器也会引发错误。这是我所看到的:
错误:“ SyntaxError:JSX值应为表达式或带引号的JSX文本”
我知道我要为“ hasvacancy”道具传递一个字符串类型的值,但是我需要做些什么,以便可以通过道具传递布尔值或其他数据类型。
import React from 'react';
import { render } from 'react-dom';
class VacancySign extends React.Component{
render() {
console.log('------------hasvacancy------', this.props.hasvacancy);
if(this.props.hasvacancy) {
return(
<div>
<p>Vacancy</p>
</div>
);
} else {
return(
<div>
<p>No-Vacancy</p>
</div>);
}
}
}
VacancySign.propTypes ={
hasvacancy: React.PropTypes.bool.isRequired
}
render(<VacancySign hasvacancy='false'/> ,
document.getElementById('root'));
您应将布尔值括在{}中:
render(<VacancySign hasvacancy={false}/> , document.getElementById('root'));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句