如何在React / Jsx中调用Render中的函数 [英] How to Call a Function inside a Render in React/Jsx

查看:1499
本文介绍了如何在React / Jsx中调用Render中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一些嵌入式html中调用一个函数。我尝试了以下但该函数未被调用。这是在render方法中调用函数的不正确方式吗?

I want to call a function inside some embedded html. I tried the following but the function isn't called. Would this be the incorrect way of calling a function inside a render method?

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>
   );
 }
}


推荐答案

调用你必须添加的函数()

To call the function you have to add ()

{this.renderIcon()}   

这篇关于如何在React / Jsx中调用Render中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆