问题描述
react中render中在turn中使用条件语句中变量未定义
class Clock extends React.Component {
render() {
let inputValue = "";
let text = "11";
return (
<div>
if(!{inputValue}){<h1>{text}</h1>}
<h1>Hello, world!</h1>
<h2>It is {this.props.date.toLocaleTimeString()}.</h2>
</div>
);
}
}
问题出现原因
return里面不能写逻辑
解决方案
逻辑写在return外面
收获
对react运行原理不了解,应该多复习官方文档