Click event and react component
See original GitHub issueI’m trying to make a react component that uses Mermaid just like this but that will allow the click event to be used. I tried the solution found here without success.
Here is what i got:
import React, { Component } from "react";
import $ from 'jquery';
import mermaid from "mermaid";
class Mimi extends Component {
constructor(props) {
super(props);
mermaid.mermaidAPI.initialize({
startOnLoad: true,
cloneCssStyles: false,
flowchart: {
useMaxWidth: true,
htmlLabels: true
}
});
}
componentDidMount() {
function myAction(id) {
alert("click firedee");
}
$(function () {
var graphDefinition = 'graph TB\nProposal-->Contract\nContract-->Planning\nPlanning-->Design\nDesign-->Build\nBuild-->Verification\nVerification-->Delivery\nDelivery-->Support\nclick Design myAction\n';
var callback = function (code,bindEvents){
console.log(bindEvents);
$("#div-id1").html(code)
bindEvents();
}
mermaid.mermaidAPI.render('some_id', graphDefinition, callback);
});
}
render() {
return (<div id={"div-id1"}></div>)
}
}
export default Mimi;
Which is called from a parent react component just like that:
<Mimi />
The FlowChart displays fine but the “Design” node that is clickable will not trigger the myAction function once clicked.
Help would be appreciated.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Handling Events - React
With JSX you pass a function as the event handler, rather than a string. For example, the HTML: <button onclick="activateLasers()"> Activate Lasers </button>....
Read more >React onClick event handlers: A complete guide
The React onClick event handler enables you to call a function and trigger an action when a user clicks an element, such as...
Read more >React onClick event on component - Stack Overflow
I have a React component called <SensorList /> that has many child <SensorItem /> s (another React component). I want to be able...
Read more >How to Use React onClick Events in Class and Functional ...
Click events are triggered when an element is clicked, and are defined in React with the event type onClick . This is passed...
Read more >React onClick Event Handling (With Examples) - Upmostly
In React, the onClick handler allows you to call a function and perform an action when an element is clicked. onClick is the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is the working react component I come up with just to test the integration with version ^8.0.0-rc.8:
@mrkchang Hey! You’re commenting in an old closed issue. Feel free to create a new issue if you found a bug, need help, want to request a feature or anything!