Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b812d97

Browse files
adds web-vitals to typescript template
1 parent c8a84ba commit b812d97

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/cra-template-typescript/template/src/index.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App';
55
import * as serviceWorker from './serviceWorker';
6+
import reportWebVitals from './reportWebVitals';
67

78
ReactDOM.render(
89
<React.StrictMode>
@@ -15,3 +16,8 @@ ReactDOM.render(
1516
// unregister() to register() below. Note this comes with some pitfalls.
1617
// Learn more about service workers: https://cra.link/PWA
1718
serviceWorker.unregister();
19+
20+
// If you want to start measuring performance in your app, pass a function
21+
// to log results (for example: reportWebVitals(console.log))
22+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
23+
reportWebVitals();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ReportHandler } from 'web-vitals';
2+
3+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4+
if (onPerfEntry && onPerfEntry instanceof Function) {
5+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6+
getCLS(onPerfEntry);
7+
getFID(onPerfEntry);
8+
getFCP(onPerfEntry);
9+
getLCP(onPerfEntry);
10+
getTTFB(onPerfEntry);
11+
});
12+
}
13+
}
14+
15+
export default reportWebVitals;

0 commit comments

Comments
 (0)