Skip to main content

useSystemTime

Returns the current time of the PC running MoBro, and optionally keeps it updated. Useful for clocks, since the device displaying the dashboard may have a different time.

function useSystemTime(props?: {autoRefresh?: boolean; refreshInterval?: number}): Date | null

Arguments

PropertyTypeDescription
autoRefreshbooleanWhether to fetch the time repeatedly. Defaults to true.
refreshIntervalnumberThe interval in milliseconds to fetch the time in. Defaults to 1000.

Every refresh fetches the time from MoBro, so avoid short intervals.

Returns

The time of the PC running MoBro, or null until it has been fetched.

Example

src/widgets/example/Example.tsx
import React from 'react'
import {useSystemTime} from '@modbros/dashboard-sdk'

export default function Example() {
const systemTime = useSystemTime({autoRefresh: true, refreshInterval: 1000})

if (!systemTime) {
return null
}

return <span>{systemTime.toLocaleTimeString()}</span>
}