-1

using react-modal, need to show the modal on click of the hyperlink either through anchor tag or react-router-dom Link

example: click on register hyperlink and register form modal should open

handleClick() =>{
 <ReactModal/>
}
<table>
<tr>
<td>
<a href='' onclick='handleClick()'>check</>
</td>
</tr>
</table>

is there a way to do that?

Sumanth
  • 159
  • 2
  • 15

1 Answers1

2

You can define onClick event handler for link. On the handler you can use preventDefault to stop navigating to the linked url. Please check below example.

const [modalVisible, setModalVisible] = useState(false);
<a
  href="https://github.com"
  onClick={(event) => {
    event.preventDefault();
    setModalVisible(true);
  }}
>
  Github
</a>
<Modal
  isOpen={modalVisible}
>
  ...
</Modal>
michael
  • 4,053
  • 2
  • 12
  • 31