Global state in OSD development

OSD 2.6

I wonder what is the best way to manage the context of the app.
I have some states I want to be shared among all components.

Currently I attached some states to the uiSettings object, but it doesn’t seems like the best idea.

That’s a good question and a big topic. Some resources that might help you get started:

To add to what @joshuarrrr there are 3 main ways you can maintain state in the app:

  1. State containers
  2. React state
  3. Your own custom solution (Highly discouraged)

State containers were used before react was apart of the project. That being said, there is no reason not to use them since they are a simple wrapper around observables. For most usecases simple react state and context should be sufficient. You can pair these state management options with url-state-storage to persist your values across refreshes. Hope this helps :slight_smile:

cool, thanks guys.
Can anyone show me some examples for getting current query state from any component?
Same for language state, filters, timestamp, and so…

I see, so you are looking to get the state of query, timefilters, etc. Its state is managed by the data plugin and can be accessed by using the query service from the data plugin once you have added it as a dependency for your plugin e.g. OpenSearch-Dashboards/workspace.tsx at main · opensearch-project/OpenSearch-Dashboards · GitHub

1 Like