// Copyright 2017-2024 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Moment } from '@polkadot/types/interfaces'; import React, { useMemo } from 'react'; import { useApi, useCall } from '@polkadot/react-hooks'; import Elapsed from './Elapsed.js'; interface Props { children?: React.ReactNode; className?: string; label?: React.ReactNode; value?: Moment; } function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement { const { api } = useApi(); const timestamp = useCall(!value && api.query.timestamp?.now); const [now, hasValue] = useMemo( () => [value || timestamp, !!(value || timestamp)], [timestamp, value] ); return (
{label || ''} {children}
); } export default React.memo(TimeNow);