React JS onClick event handler

前端 未结 11 1141
孤街浪徒
孤街浪徒 2020-11-28 21:35

I have

var TestApp = React.createClass({
      getComponent: function(){
          console.log(this.props);
      },
      render: function(){
        retur         


        
11条回答
  •  被撕碎了的回忆
    2020-11-28 21:42

    Here is how you define a react onClick event handler, which was answering the question title... using es6 syntax

    import React, { Component } from 'react';
    
    export default class Test extends Component {
      handleClick(e) {
        e.preventDefault()
        console.log(e.target)
      }
    
      render() {
        return (
           this.handleClick(e)}>click me
        )
      }
    }
    

提交回复
热议问题