this.props.onclick code example

Example 1: react button onclick

import React, { Component } from 'react';

class App extends Component {
  
  constructor(props) {
    super(props);
    this.sayHello = this.sayHello.bind(this);
  }

  sayHello() {
    alert('Hello!');
  }
  
  return (
    
  );
}

export default App;

Example 2: react button onclick

import React from 'react';

function App() {

  function sayHello() {
    alert('Hello!');
  }
  
  return (
    
  );
}

export default App;

Example 3: using props in function component for onclick event

const HelloWorld = ({ dispatch }) => {
  const handleClick = useCallback(() => {
    dispatch(something())
  })
  return 

Tags:

Misc Example