最佳答案
我来从使用棱角反应,我试图找出一个好的反应替代棱角的 ng-if 指令,我渲染或不渲染一个元素的条件。以这段代码为例。顺便说一下,我使用的是打字稿(tsx) ,不过这应该没什么关系。
"use strict";
import * as React from 'react';
interface MyProps {showMe: Boolean}
interface MyState {}
class Button extends React.Component <MyProps, MyState>{
constructor(props){
super(props);
this.state = {};
}
render(){
let button;
if (this.props.showMe === true){
button = (
<button type="submit" className="btn nav-btn-red">SIGN UP</button>
)
} else {
button = null;
}
return button;
}
}
export default Button;
这个解决方案是有效的,但是有没有其他的方法可以达到这个效果呢? 我只是在猜测