How to Call a Function inside a Render in React/Jsx
refer https://stackoverflow.com/questions/40298136/how-to-call-a-function-inside-a-render-in-react-jsx
在某个页面想要根据不同的条件进行渲染,可以使用函数调用,例如:(根据情况,在renderIcon中自行增加判断)
import React, { Component, PropTypes } from 'react';
export default class PatientTable extends Component {
constructor(props) {
super(props);
this.renderIcon = this.renderIcon.bind(this); // 增加这一行
this.state = {
checking:false
};
}
// 增加这一段
renderIcon(){
console.log("came here")
return(
<div>Function called</div>
)
}
render() {
return (
<div className="patient-container">
{this.renderIcon()} // 增加这一行
</div>
);
}
}