Skip to main content

Custom Connection Status Message

By default, the header bar shows either an "Online" or "Offline" message based on whether the app can connect to the DHIS2 server. If it's useful for an app to share other relevant info in that badge, for example "3 changes saved locally", then it's possible to set a custom message there:

Custom online status message

Hooks​

import {
useSetOnlineStatusMessage,
useOnlineStatusMessageValue,
useOnlineStatusMessage,
} from '@dhis2/app-runtime'

useSetOnlineStatusMessage​

It's most likely that you'll only use useSetOnlineStatusMessage(), a hook that returns a setState function. It can set the value in the Header Bar without causing a rerender for itself.

setOnlineStatusMessage() accepts a ReactNode-type object, so icons or other components can be added to the badge, but don't go crazy. A simple string is also a valid ReactNode:

const setOnlineStatusMessage: (message: ReactNode) => void =
useSetOnlineStatusMessage()

useOnlineStatusMessageValue​

This hook returns just the value:

const onlineStatusMessage: ReactNode = useOnlineStatusMessageValue()

useOnlineStatusMessage​

This hook returns both the value and the set function:

const { onlineMessage, setOnlineStatusMessage } = useOnlineStatusMessage()

Example​

You can see an example in use in the Aggregate Data Entry app