Calling a function in React

前端 未结 6 1978
感动是毒
感动是毒 2021-02-04 21:55

I\'m a beginner in React, and I\'m a little confused about calling a function in React.

I saw the following ways and I don\'t know when to use each and which one.

<
6条回答
  •  一个人的身影
    2021-02-04 22:35

    You can trigger events with this.props.someProps(). Check the following sample.

    import React, { Component } from 'react';    
    
    class AddToDo extends Component {
       render() {
          return (
             
          )
       }
    }
    
    class Todos extends Component {
       handleAddToDo(ev, someVal) {
          // do something
       }
    
       render() {
          return (
              this.handleAddToDo(ev, someVal)} />
          )
       }
    }
    
    export default Todos;
    

提交回复
热议问题