Are you first timer at Why not join us and start exchange your programming knowledge with everyone. Register today!

React - Handling events

0 votes
added Mar 8 in React by LC Marshal Lieutenant (16,990 points)

In order to prevent HTML default link from opening new page, you simply code:

<a href="#" onclick="console.log('I get clicked.'); return false">
  Click here


In react, you need to do it with  preventDefault

// React
function LinkMe() {
  function handleClick(e) {
    console.log('I get clicked');

  return (
    <a href="#" onClick={handleClick}>
      Click here 


Please log in or register to response this reference. - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.