Links with `onClick` and `href` compete for event handling
Closed this issue ยท 1 comments
onebit0fme commented
Whenever <a href="#" onClick={handlerFunction}>Link</a>
is used, for example here:
the proper way is to prevent default behaviour in the callback function with e.preventDefault()
, otherwise page will navigate to #
, which would probably result in jumping to the top of the page.
This issue applies to any <a>
tag that uses href
. Note, some answers suggest that <a href="#" onClick={() => handlerFunction()}>Link</a>
doesn't suffer from this, but this solution behaves the same.
onebit0fme commented
Addressed in #5