Every interaction in the Gantt — drag, drop, edit, add, delete — flows through a central event bus. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/svar-widgets/react-gantt/llms.txt
Use this file to discover all available pages before exploring further.
IApi object you receive from the init prop is your handle to that bus.
Receiving the API
Pass a callback to theinit prop. It is called once, synchronously, after the Gantt store is initialised.
useCallback to subscribe to events before the component re-renders:
The
init callback is also exposed as the ref forwarding target. You can get the API via a React ref: <Gantt ref={ganttRef} ... /> and then ganttRef.current.exec(...).api.on() — subscribing to events
api.on(eventName, handler) subscribes to an event after it has been processed. Use this for side effects such as logging, syncing to external state, or triggering secondary actions.
api.on() returns an unsubscribe function:
api.exec() — dispatching actions
api.exec(actionName, payload) triggers any action programmatically — the same actions the UI dispatches internally.
All built-in action names
| Action | Key payload fields | Description |
|---|---|---|
add-task | task, target, mode | Insert a new task. |
update-task | id, task | Update task fields. |
delete-task | id | Delete a task and its subtree. |
select-task | id | Set the selected task. |
move-task | id, mode ('up'/'down') | Reorder in the list. |
indent-task | id | Make the task a child of the one above. |
outdent-task | id | Move the task one level up. |
drag-task | id, start, end, top | Drag on the chart. |
show-editor | id | Open/close the editor. |
add-link | link | Create a dependency link. |
delete-link | id | Delete a link. |
update-link | id, link | Update a link. |
scroll-chart | left | Programmatic chart scroll. |
provide-data | id, data | Feed lazy-loaded child data. |
undo | — | Undo last action. |
redo | — | Redo last undone action. |
api.intercept() — blocking or modifying actions
api.intercept(actionName, handler) runs your callback before the action is processed. Return false to cancel; return a modified payload object to change the action’s data.
Callback event props
As an alternative toapi.on(), you can pass event handler props directly on <Gantt>. The prop name is the camelCase action name prefixed with on.
api.on() handlers.
api.getState() and api.getReactiveState()
api.getState() returns a plain snapshot of the current store state. Use it for one-time reads.
api.getReactiveState() returns a reactive store object you can subscribe to outside of React:
api.getTask(id)
Read a single task from the store by id:api.serialize()
Export the full current state (tasks and links) as a plain JSON-serialisable object:setNext — chaining handlers
api.setNext(handler) inserts a custom handler into the action processing pipeline. This is how RestDataProvider from @svar-ui/gantt-data-provider intercepts actions to sync changes to the server.
setNext.
Quick reference
| Method | When to use |
|---|---|
api.on(event, fn) | Side effects after an action completes. |
api.exec(action, payload) | Trigger any action programmatically. |
api.intercept(action, fn) | Block or modify an action before it runs. |
api.getState() | One-time synchronous state snapshot. |
api.getReactiveState() | Subscribe to store changes outside React. |
api.getTask(id) | Read a single task from the store. |
api.serialize() | Export tasks and links as plain objects. |
api.setNext(handler) | Insert a middleware step in the action pipeline. |
api.detach(fn) | Remove a previously attached on/intercept handler. |