import React from 'react'; import { numberWithCommas } from 'App/utils'; import styles from './loadInfo.module.css'; const LoadInfo = ({ webvitals, event: { fcpTime, visuallyComplete, timeToInteractive }, prorata: { a, b, c }, }) => (
{typeof fcpTime === 'number' &&
} {typeof visuallyComplete === 'number' && (
)} {typeof timeToInteractive === 'number' && (
)}
{typeof fcpTime === 'number' && (
{'Time to Render'}
{`${numberWithCommas( fcpTime || 0 )}ms`}
)} {typeof visuallyComplete === 'number' && (
{'Visually Complete'}
{`${numberWithCommas( visuallyComplete || 0 )}ms`}
)} {typeof timeToInteractive === 'number' && (
{'Time To Interactive'}
{`${numberWithCommas( timeToInteractive || 0 )}ms`}
)} {webvitals ? Object.keys(webvitals).map((key) => ( )) : null}
); function WebVitalsValue({ name, value }) { const valInt = Number(value); const valDisplay = name !== 'CLS' ? Math.round(valInt) : valInt > 1 ? Math.round(valInt) : valInt.toExponential(1).split('e'); const unit = { CLS: 'score', FCP: 'ms', INP: 'ms', LCP: 'ms', TTFB: 'ms', }; return (
{name}
{Array.isArray(valDisplay) ? ( <> {valDisplay[0]}× 10{valDisplay[1]} ) : ( <> {valDisplay} {unit[name]} )}
); } const WebVitalsValueMemo = React.memo(WebVitalsValue); LoadInfo.displayName = 'LoadInfo'; export default React.memo(LoadInfo);