我想在一些嵌入的 html 中调用一个函数。我尝试了以下但未调用该函数。这是在 render 方法中调用函数的错误方式吗?
import React, { Component, PropTypes } from 'react';
export default class PatientTable extends Component {
constructor(props) {
super(props);
this.state = {
checking:false
};
this.renderIcon = this.renderIcon.bind(this);
}
renderIcon(){
console.log("came here")
return(
<div>Function called</div>
)
}
render() {
return (
<div className="patient-container">
{this.renderIcon}
</div>
);
}
}
最佳答案
要调用该函数,您必须添加 ()
{this.renderIcon()}
关于javascript - 如何在 React/Jsx 的渲染中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40298136/