Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React.js onClick return event

I had properly working link with JS onclick attribute on a CMS, the code looked like this:

<a class="button is-success" onclick="return klaro.show();">click</a>

it was opening the model window.
Now I’m trying to replicate this on an old React.js project.
I remember, that there are a few language notations, but as I’m not working at all with this language it’s difficult for me.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve these kind of links:

    <li><a href="#link">{t('Link')}</a></li>
    <li><a class="button is-success" onclick="return klaro.show();">{t('cookie choice')}</a></li>

But since it’s React the last link is not working. I tried to change it to <a className="button is-success" onClick={() => "return klaro.show();"}>člick</a> but the onClick event is absent once the page is rendered.

How should it be done correctly with this notation?

>Solution :

Use this

<li><a href="#link">{t('Link')}</a></li>
<li><a class="button is-success" onClick={klaro.show}>{t('cookie choice')}</a></li>

Or Use Like This

<li><a href="#link">{t('Link')}</a></li>
<li><a class="button is-success" onClick={() => klaro.show()}>{t('cookie choice')}</a></li>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading