如何在React/Jsx中调用Render中的函数
发布时间:2020-12-15 20:54:41 所属栏目:百科 来源:网络整理
导读:我想在一些嵌入式html中调用一个函数。我尝试了以下但是没有调用该函数。这是在render方法中调用函数的错误方法吗? import React,{ Component,PropTypes } from 'react';export default class PatientTable extends Component { constructor(props) { super
我想在一些嵌入式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()} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |