api.on()
Description
Allows attaching a handler to the inner eventsUsage
api.on(
(event, handler) => {
// your code here
}
);
Parameters
event
- (required) an event to be firedhandler
- (required) a handler to be attached (the handler arguments will depend on the event to be fired)
info
The full list of actions can be found here.
Use the api.on()
method if you want to listen to the actions without modifying them. To make changes to the actions, apply the api.intercept()
method.
Example
import { useEffect, useRef } from "react";
import { getData } from "./common/data";
import { Gantt } from "wx-react-gantt";
import "wx-react-gantt/dist/gantt.css";
const data = getData();
function GanttComponent() {
const apiRef = useRef();
useEffect(() => {
if (apiRef.current) {
apiRef.current.on("delete-link", (ev) => {
console.log("The id of the deleted link:", ev.id);
});
}
}, [apiRef.current]);
return (
<Gantt
apiRef={apiRef}
tasks={data.tasks}
links={data.links}
//other settings
/>
);
}
export default GanttComponent;
Related articles: