即使我已经应用了propType验证,我的编辑器在为hasvacancy
属性传递布尔值时仍然抛出一个错误。这是我所看到的:
错误:'SyntaxError: jsx值应该是表达式或带引号的JSX文本‘
我知道我传递的是一个字符串类型值,但是我需要做什么才能通过这个prop传递一个布尔值或其他数据类型呢?
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'));
https://stackoverflow.com/questions/39326300
复制相似问题