Skip to main content

api.setNext()

Description

Allows adding some action into the Event Bus order

Usage

api.setNext(next: any): void;

Parameters

  • next - (required) the action to be included into the Event Bus order

Example

You need to include RestDataProvider into the Event Bus order to perform operations with tasks and send the corresponding requests to the server.

Example:

import React, { useEffect, useState, useRef } from "react";
import { Gantt } from "wx-react-gantt";
import "wx-react-gantt/dist/gantt.css";
import { RestDataProvider } from "wx-gantt-data-provider";
import { getData } from "./common/data";

const GanttComponent = () => {
const data = getData();
const url = "https://some_backend_url";
const server = new RestDataProvider(url);

const [tasks, setTasks] = useState([]);
const [links, setLinks] = useState([]);
const apiRef = useRef();

useEffect(() => {
server.getData().then(data => {
setTasks(data.tasks);
setLinks(data.links);
});
}, [server]);

useEffect(() => {
if (apiRef.current) {
apiRef.current.setNext(server);
}
}, [apiRef.current, server]);

return (
<Gantt
tasks={tasks}
links={links}
ref={apiRef}
/>
);
};

export default GanttComponent;

Related articles: