Skip to main content

api.getState()

Description

Gets the state object that stores current values of most Gantt properties

You can apply the method to get the state of tasks, links, columns, scales, etc. See the parameters of the returned object below.

Usage

api.getState(): object;

Returns

The method returns an object with the following parameters:

{
tasks,
links,
start,
columns,
end,
lengthUnit,
cellWidth,
cellHeight,
scaleHeight,
scales,
taskTypes,
zoom,
selected,
activeTask,
baselines,
}

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 GanttComponent = () => {
const data = getData();
const apiRef = useRef();

useEffect(() => {
if (apiRef.current) {
const { tasks, links } = apiRef.current.getState();
console.log(tasks); //output the state of tasks
console.log(links); //output the state of links
}
}, [apiRef.current]);

return <Gantt ref={apiRef} tasks={data.tasks} links={data.links} />;
};

export default GanttComponent;

Related articles: