Adaptable

#useAdaptableState

useAdaptableState() gives you the Adaptable state — or a part of it — in any component rendered inside <Adaptable.Provider />. Your component re-renders when the value you read changes.

import { useAdaptableState } from '@adaptabletools/datagrid-react';
Note

To run code when the state changes (logging, syncing to a server) without re-rendering, use useAdaptableStateSubscribe.

#Usage

Call it without arguments to get the whole state:

const adaptableState = useAdaptableState();

Or pass a selector function to pick the part you are interested in:

Getting the id of the active view
const currentViewId = useAdaptableState((state) => state.view.currentViewId);
Getting the applied theme
const theme = useAdaptableState((state) => state.theme.currentTheme);

Prefer a selector: without one, the component re-renders on every state change. The selector receives the full AdaptableState; the slices are described in the state reference.

For common reads, the dedicated hooks are shorter — useCurrentViewState for the active view, or the feature hooks (useViews, useTheme, …), which also return the setters.

#
Reading the state with useAdaptableState

The current view is read from the state in two places: the line above the grid (view label and theme) and the header of the First name column (view id), rendered through the column's renderHeader.

Switch the view from the dashboard to see both update.

open
loading demo…