Home > widget-integration > FilterStore > setState

FilterStore.setState() method

Updates the filter state with new values and notifies all watchers.

This method merges the provided partial state with the current state and triggers notifications to all registered watchers. Override this method to add custom validation or transformation logic before state updates.

Signature:

setState(newState: Partial<FilterStates>): void;

Parameters

Parameter

Type

Description

newState

Partial<FilterStates>

Partial state object with properties to update. Only provided properties will be updated; others remain unchanged.

Returns:

void

Example

Extend to add state validation:

window.boostWidgetIntegration.extend('FilterStore', (FilterStore) => {
  return class CustomFilterStore extends FilterStore {
    setState(newState) {
      // Validate before updating
      if (newState.latestRequestKey && !this.isValidKey(newState.latestRequestKey)) {
        console.warn('Invalid request key');
        return;
      }
      super.setState(newState);
    }
  };
});