【发布时间】:2018-08-03 19:24:34
【问题描述】:
我有这个输入组件
<input
onBlur={invalidEmail ? 'Your email is invalid' : null}
/>
如果我这样做了
<input
onBlur={errorFunction}
/>
errorFunction = () => {
return invalidEmail ? 'Your email is invalid' : null
}
忘记变量名,假设所有变量都来自状态等
为什么第一个有效而第二个无效?
【问题讨论】:
-
why would the first one work and the second one not?你确定吗?因为我认为第二个会起作用,而不是第一个。 -
你需要添加 this.errorFunction 代替 errorFunction
-
你检查过解决方案了吗?
标签: reactjs return ternary-operator