#useAdaptableStateSubscribe
useAdaptableStateSubscribe() is a composable that runs a callback whenever a
part of the Adaptable state changes. Unlike
useAdaptableState, it returns nothing, so
nothing in your component is updated — use it for side effects: logging,
analytics, syncing a value to your server or to another part of your app.
Call it in <script setup> (or in setup()) of a component rendered inside
<Adaptable.Provider>:
import { useAdaptableStateSubscribe } from '@adaptabletools/datagrid-vue';
useAdaptableStateSubscribe({
selector: (state) => state.view.currentViewId,
callback: (viewId, oldViewId, { adaptableApi }) => {
console.log('view changed from', oldViewId, 'to', viewId);
},
});#Parameters
The composable takes one object:
callback—(value, oldValue, context) => void. Called when the value returned byselectorchanges, with the new and the previous value.context.adaptableApiis the Adaptable API.equals— optional(a, b) => boolean. Decides whether two selected values are equal. Defaults toObject.is, so pass one when your selector builds a new object or array each time.selector—(state: AdaptableState) => value. Picks the part of the state you are interested in.
The subscription is made once, when the composable is called, with the
selector and equals of that call, and ends when the component is
unmounted. There is nothing to memoize: write the selector and the callback
inline. The callback can read your refs; it reads them when it runs.
To listen from outside a component, pass the same
{ selector, callback, equals } objects to the
onStateChangeWithSelectors prop, or use
onStateChange to be notified of every change.
Two subscriptions append to the log above the grid: one on
state.view.currentViewId, one on state.quickSearch.searchText.
Switch the view or type in the quick search box to see new entries.