Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
How to render button onClick function in reactjs using react-markdown

I am trying to alert a button in react-markdown.

This is the code below:

import React, {useState, useEffect} from "react";
import {useNavigate} from "react-router-dom";
import '../App.css';
import ReactMarkdown from "react-markdown";
import remarkGfm from 'remark-gfm'
import rehypeRaw from "rehype-raw"



function App() {

  const navigate=useNavigate()

  const handleClick=(e)=>{
    alert("Hello")
    e.preventDefault()
  }
  
    
  const source = `

  # Plugin

  <button onClick=${handleClick}> Click Me </button>
  
  `

  return (
    <div className="App">
      
      <ReactMarkdown children={source} rehypePlugins={[rehypeRaw]} remarkPlugins={[remarkGfm]} />
        
    </div>
  );
}


export default App 

After visiting the url I am getting either like this:

<button onClick=e => { alert("Hello"); e.preventDefault(); }> Click Me
 

or alert button keeps popping.

someone please help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please try this approach

<button onClick={(e)=>{alert('I am Alert')}>
  Click Me
</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!