Skip to content

Commit e5760ac

Browse files
committed
upgrade react version to 18; add comments;
1 parent 39c0418 commit e5760ac

File tree

8 files changed

+49
-12
lines changed

8 files changed

+49
-12
lines changed

1.hello-world/13.read-video-react-ts/src/components/VideoDecode/VideoDecode.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import React from 'react';
33
import './VideoDecode.css'
44

55
class VideoDecode extends React.Component {
6-
pScanner: Promise<BarcodeScanner> = BarcodeScanner.createInstance();
6+
pScanner: Promise<BarcodeScanner>|null = null;
77
elRef: React.RefObject<HTMLDivElement> = React.createRef();
88
async componentDidMount() {
99
try {
10-
const scanner = await this.pScanner;
10+
const scanner = await (this.pScanner = BarcodeScanner.createInstance());
11+
// Should judge if scanner is destroyed after 'await' in React 18 'StrictMode'.
12+
if(scanner.isContextDestroyed()) return;
1113
await scanner.setUIElement(this.elRef.current!);
14+
// Should judge if scanner is destroyed after 'await' in React 18 'StrictMode'.
15+
if(scanner.isContextDestroyed()) return;
1216
scanner.onFrameRead = results => {
1317
for (let result of results) {
1418
console.log(result.barcodeText);

1.hello-world/13.read-video-react-ts/src/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import App from './App';
5+
import reportWebVitals from './reportWebVitals';
56

6-
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
7+
const root = ReactDOM.createRoot(
8+
document.getElementById('root') as HTMLElement
9+
);
10+
root.render(
11+
<React.StrictMode>
12+
<App />
13+
</React.StrictMode>
14+
);
715

8-
root.render(<App />);
16+
// If you want to start measuring performance in your app, pass a function
17+
// to log results (for example: reportWebVitals(console.log))
18+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
19+
reportWebVitals();
Lines changed: 15 additions & 0 deletions
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;

1.hello-world/4.read-video-react/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"@testing-library/react": "^11.1.0",
99
"@testing-library/user-event": "^12.1.10",
1010
"dynamsoft-javascript-barcode": "9.6.0",
11-
"react": "^17.0.1",
12-
"react-dom": "^17.0.1",
13-
"react-scripts": "4.0.3",
11+
"react": "^18.2.0",
12+
"react-dom": "^18.2.0",
13+
"react-scripts": "^4.0.3",
1414
"web-vitals": "^1.0.1"
1515
},
1616
"scripts": {

1.hello-world/4.read-video-react/src/components/VideoDecode/VideoDecode.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

1.hello-world/4.read-video-react/src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
33
import './index.css';
44
import App from './App';
55
import reportWebVitals from './reportWebVitals';
66

7-
ReactDOM.render(
7+
const container = document.getElementById('root');
8+
const root = createRoot(container); // createRoot(container!) if you use TypeScript
9+
root.render(
810
<React.StrictMode>
911
<App />
10-
</React.StrictMode>,
11-
document.getElementById('root')
12+
</React.StrictMode>
1213
);
1314

1415
// If you want to start measuring performance in your app, pass a function

1.hello-world/6.read-video-vue3/src/components/VideoDecode.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default {
8181
}
8282
};
8383
scanner.onUniqueRead = (txt, result) => {
84-
alert(txt, result);
84+
alert(txt);
8585
}
8686
await scanner.open();
8787
} catch (ex) {

1.hello-world/7.read-video-nextjs/components/VideoDecode.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)