summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2022-08-29 09:52:34 +0300
committerYuval Adam <_@yuv.al>2022-08-29 09:52:49 +0300
commit998b5cda31aa14a443861568edfc113065d660bb (patch)
tree6aff0700e96d5ddef3be9a9158594c8f98310bb4 /src
parent544b1b1f57755491130864ed71e3cf0ae985b66f (diff)
Copy over template from new react scripts project
Diffstat (limited to 'src')
-rw-r--r--src/index.js17
-rw-r--r--src/reportWebVitals.js13
-rw-r--r--src/serviceWorker.js16
-rw-r--r--src/setupTests.js5
4 files changed, 39 insertions, 12 deletions
diff --git a/src/index.js b/src/index.js
index dbc6663..a18f675 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,11 +1,20 @@
import React from 'react';
-import ReactDOM from 'react-dom';
+import ReactDOM from 'react-dom/client';
import './index.css';
import App from './Geshem';
-import * as serviceWorker from './serviceWorker';
+import reportWebVitals from './reportWebVitals';
console.log()
-ReactDOM.render(<App />, document.getElementById('root'));
-serviceWorker.unregister();
+const root = ReactDOM.createRoot(document.getElementById('root'));
+root.render(
+ <React.StrictMode>
+ <App />
+ </React.StrictMode>
+);
+
+// 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();
diff --git a/src/reportWebVitals.js b/src/reportWebVitals.js
new file mode 100644
index 0000000..5253d3a
--- /dev/null
+++ b/src/reportWebVitals.js
@@ -0,0 +1,13 @@
+const reportWebVitals = onPerfEntry => {
+ if (onPerfEntry && onPerfEntry instanceof Function) {
+ import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
+ getCLS(onPerfEntry);
+ getFID(onPerfEntry);
+ getFCP(onPerfEntry);
+ getLCP(onPerfEntry);
+ getTTFB(onPerfEntry);
+ });
+ }
+};
+
+export default reportWebVitals;
diff --git a/src/serviceWorker.js b/src/serviceWorker.js
index 2283ff9..85daadc 100644
--- a/src/serviceWorker.js
+++ b/src/serviceWorker.js
@@ -12,12 +12,12 @@
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
- // [::1] is the IPv6 localhost address.
- window.location.hostname === '[::1]' ||
- // 127.0.0.1/8 is considered localhost for IPv4.
- window.location.hostname.match(
- /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
- )
+ // [::1] is the IPv6 localhost address.
+ window.location.hostname === '[::1]' ||
+ // 127.0.0.1/8 is considered localhost for IPv4.
+ window.location.hostname.match(
+ /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
+ )
);
export function register(config) {
@@ -43,7 +43,7 @@ export function register(config) {
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
- 'worker. To learn more, visit http://bit.ly/CRA-PWA'
+ 'worker. To learn more, visit http://bit.ly/CRA-PWA'
);
});
} else {
@@ -71,7 +71,7 @@ function registerValidSW(swUrl, config) {
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
- 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
+ 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
);
// Execute callback
diff --git a/src/setupTests.js b/src/setupTests.js
new file mode 100644
index 0000000..8f2609b
--- /dev/null
+++ b/src/setupTests.js
@@ -0,0 +1,5 @@
+// jest-dom adds custom jest matchers for asserting on DOM nodes.
+// allows you to do things like:
+// expect(element).toHaveTextContent(/react/i)
+// learn more: https://github.com/testing-library/jest-dom
+import '@testing-library/jest-dom';