Creating custom function in React component

前端 未结 4 673
南旧
南旧 2021-01-30 19:58

I have a React component

export default class Archive extends React.Component { 
   ...
}

componentDidMount and onClick

4条回答
  •  别那么骄傲
    2021-01-30 20:33

    Another way:

    export default class Archive extends React.Component { 
    
      saySomething = (something) => {
        console.log(something);
      }
    
      handleClick = (e) => {
        this.saySomething("element clicked");
      }
    
      componentDidMount() {
        this.saySomething("component did mount");
      }
    
      render() {
        return 

    In this format you don't need to use bind

提交回复
热议问题