Console.log by clicking button

Inline

<button onClick={() => console.log(123)}>Click</button>

Function

const handleClick = () => {
    console.log('Clicked');
};
<button onClick={() => handleClick()} >
  Clicked
</button>

Catch and console.log the id

<button onClick={() => handleClick(item.id)}>
  Display ID in the console
</button>
const handleClick = (id) => {
    console.log(id);
};
Was this page helpful?