cra-template-bod
Version:
The advanced TypeScript template for Bod CLI.
21 lines (18 loc) • 613 B
text/typescript
import type { MetricType } from 'web-vitals'
/**
* Reports web vitals to the provided callback function.
* @param {(metric: MetricType) => void} onPerfEntry The callback function to receive the web vitals data.
* @returns {void}
*/
function reportWebVitals(onPerfEntry?: (metric: MetricType) => void) {
if (onPerfEntry && typeof onPerfEntry === 'function') {
import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {
onCLS(onPerfEntry)
onINP(onPerfEntry)
onFCP(onPerfEntry)
onLCP(onPerfEntry)
onTTFB(onPerfEntry)
})
}
}
export default reportWebVitals