Events


It is good convention to have event handlers defined as methods in the component class.

method_HandleEvent = event => { 
   this.setState({ string : this.state.sText === 'a' ? 'b' : 'a' })
}


class MyButton extends React.Component { 
   render() {
      return (
         <button onClick = { anyGlobalFunction } >
         </button>
      );
   }
}

Or it can be defined on the class component as an instance property

class MyButton extends React.Component { 
   handleOnClick = () => { anyGlobalFunction };

   render() {
      return (
         <button onClick = { this.handleOnClick } >
         </button>
      );
   }
}

This is equivalent to

<MyButton onClick = { () => { anyGlobalFunction }  } > 



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext