-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HgReact.ts
44 lines (36 loc) · 1.33 KB
/
HgReact.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
import { createRoot, hydrateRoot } from "react-dom/client";
import { MetricType } from "web-vitals/src/types/base";
import { reportWebVitals } from "./reportWebVitals";
import { LogService } from "../core/LogService";
const LOG = LogService.createLogger( 'HgReact' );
/**
* Initializes React or React SSR
*/
export class HgReact {
/**
* This method will initialize ReactJS.
*/
public static initialize (
app : any,
rootElementId : string = 'root'
) : void {
const container = document.getElementById(rootElementId);
if (container) {
if (container.innerHTML !== "") {
hydrateRoot( container, app );
} else {
const root = createRoot( container );
root.render(app);
}
} else {
LOG.error(`Could not find root element: ${rootElementId}`);
}
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals((metric: MetricType): void => {
LOG.debug(`web vitals: `, metric);
});
}
}