xxxxxxxxxx
import React from 'react';
const ExampleComponent = () => {
function sayHello(name) {
alert(`hello, ${name}`);
}
return (
<button onClick={() => sayHello('James')}>Greet</button>
);
xxxxxxxxxx
For developers developing in class based components only, you have to use the arrow function.
You can't call it like any other parameter-less function.