【发布时间】:2018-01-16 07:35:21
【问题描述】:
我正在尝试在以下示例代码中的 const def = (props) => { 行修复此 lint 错误。
const propTypes = {
prop1: PropTypes.string,
prop2: PropTypes.string,
prop3: PropTypes.string,
prop4: PropTypes.string,
prop5: PropTypes.string,
}
const abc = (props) => {
some code here }
const def = (props) => {
<div>
<div className=" ..some classes..">{abc}</div>
<div className=" ..some classes..">{t('translation/something')}</div>
<div ...>
<someComponent
do something
/>
if (some condition) {
do this
} else {
do that
}
</div>
};
知道为什么我会收到此 lint 错误吗?
【问题讨论】:
-
那行没有问题。这是在你得到 HTML 而不是 JS 之后的那一行。
-
你不能在 jsx 中拥有和
if。您需要使用condition ? if true : if false语法。 -
即使我只是执行
const def = (props) => { <div> </div> };,我也会遇到同样的 lint 错误