Skip to main content

setNext

Appends a handler to the end of the event bus chain so it receives every dispatched action after the built-in handlers run. RestDataProvider uses this method to connect to the kanban: it registers its REST handlers as the "next" link in the chain and forwards card mutations to the backend.

Usage​

setNext(handler: any): any;

The handler is typically an object with its own action-handling methods (like the one returned by RestDataProvider). Returns the passed handler.

Every dispatched action passes through the chain in this order:

  1. The store applies the action.
  2. The EventBusRouter calls the matching host on{Action} prop, such as onMoveCard.
  3. Handlers added with setNext run in the order they were added.

Adding a handler doesn't replace the on{Action} props. They keep firing before the handler. If the store rejects an action, for example a move-card to an unknown column, the action isn't forwarded: neither the on{Action} props nor the setNext handlers receive it.

Example​

Attaching a REST data provider:

import { useState } from "react";
import { Kanban, RestDataProvider } from "@svar-ui/react-kanban";

const url = "https://api.example.com";
const provider = new RestDataProvider(url);

function App() {
const [cards, setCards] = useState([]);

async function init(api) {
api.setNext(provider);
setCards(await provider.getData());
}

return <Kanban cards={cards} columns={columns} init={init} />;
}

export default App;