` component.
```jsx
import { OpenSearchDashboardsContextProvider } from 'opensearch-dashboards-react';
```
## Accessing context
Using `useOpenSearchDashboards` hook.
```tsx
import { useOpenSearchDashboards } from 'opensearch-dashboards-react';
const Demo = () => {
const opensearchDashboards = useOpenSearchDashboards();
return {opensearchDashboards.services.uiSettings.get('theme:darkMode') ? 'dark' : 'light'}
;
};
```
Using `withOpenSearchDashboards()` higher order component.
```tsx
import { withOpenSearchDashboards } from 'opensearch-dashboards-react';
const Demo = ({ opensearchDashboards }) => {
return {opensearchDashboards.services.uiSettings.get('theme:darkMode') ? 'dark' : 'light'}
;
};
export default withOpenSearchDashboards(Demo);
```
Using `` render prop.
```tsx
import { UseOpenSearchDashboards } from 'opensearch-dashboards-react';
const Demo = () => {
return (
{(opensearchDashboards) => {opensearchDashboards.services.uiSettings.get('theme:darkMode') ? 'dark' : 'light'}
}
);
};
```
## `uiSettings` service
Wrappers around Core's `uiSettings` service.
### `useUiSetting` hook
`useUiSetting` synchronously returns the latest setting from `CoreStart['uiSettings']` service.
```tsx
import { useUiSetting } from 'opensearch-dashboards-react';
const Demo = () => {
const darkMode = useUiSetting('theme:darkMode');
return {darkMode ? 'dark' : 'light'}
;
};
```
#### Reference
```tsx
useUiSetting(key: string, defaultValue: T): T;
```
### `useUiSetting$` hook
`useUiSetting$` synchronously returns the latest setting from `CoreStart['uiSettings']` service and
subscribes to changes, re-rendering your component with latest values.
```tsx
import { useUiSetting$ } from 'opensearch-dashboards-react';
const Demo = () => {
const [darkMode] = useUiSetting$('theme:darkMode');
return {darkMode ? 'dark' : 'light'}
;
};
```
#### Reference
```tsx
useUiSetting$(key: string, defaultValue: T): [T, (newValue: T) => void];
```
## `overlays` service
Wrapper around Core's `overlays` service, allows you to display React modals and flyouts
directly without having to use `react-dom` library to mount to DOM nodes.
```tsx
import { createOpenSearchDashboardsReactContext } from 'opensearch-dashboards-react';
class MyPlugin {
start(core) {
const {
value: { overlays },
} = createOpenSearchDashboardsReactContext(core);
overlays.openModal(Hello world!
);
}
}
```
- `overlays.openModal` — opens modal window.
- `overlays.openFlyout` — opens right side panel.
You can access `overlays` service through React context.
```tsx
const Demo = () => {
const { overlays } = useOpenSearchDashboards();
useEffect(() => {
overlays.openModal(Oooops! {errorMessage}
);
}, [errorMessage]);
};
```
## `notifications` service
Wrapper around Core's `notifications` service, allows you to render React elements
directly without having to use `react-dom` library to mount to DOM nodes.
```tsx
import { createOpenSearchDashboardsReactContext } from 'opensearch-dashboards-react';
class MyPlugin {
start(core) {
const {
value: { notifications },
} = createOpenSearchDashboardsReactContext(core);
notifications.toasts.show({
title: Hello
,
body: world!
,
});
}
}
```
- `notifications.toasts.show()` — show generic toast message.
- `notifications.toasts.success()` — show positive toast message.
- `notifications.toasts.warning()` — show warning toast message.
- `notifications.toasts.danger()` — show error toast message.
You can access `notifications` service through React context.
```tsx
const Demo = () => {
const { notifications } = useOpenSearchDashboards();
useEffect(() => {
notifications.toasts.danger({
title: 'Oooops!',
body: errorMessage,
});
}, [errorMessage]);
};
```
## RedirectAppLinks
Utility component that will intercept click events on children anchor (``) elements to call
`application.navigateToUrl` with the link's href. This will trigger SPA friendly navigation
when the link points to a valid OpenSearch Dashboards app.
```tsx
Go to another-app
```