Hello
It appears that there is an inconsistency of getReactiveState() usage in the example provided in the documentation, which may be causing the confusion and the error you're encountering.
Thank you for informing us about this discrepancy in the documentation, we have already fixed it.
In the meantime, to subscribe to state changes with the help of the getReactiveState method, you should use it this way:
apiRef.current.getReactiveState().selected.subscribe((val) => {
setSelected(val); //val is an array
});
Please check the example: https://stackblitz.com/edit/vitejs-vite-ztns9gvv?file=src%2FGanttComponent.jsx
There are also 2 more ways:
1 Use getState instead of getReactiveState. It returns an object with static values. This does not subscribe to state changes but allows you to know its state at any moment.
2 Subscribe to state changes through the necessary events. For example, for selection, you can use select-task and get the new value through the event parameter:
apiRef.current.on('select-task', (ev) => {
setSelected(ev.id); //id of the task being selected
});