Skip to content

Commit a31e908

Browse files
committed
fix: remove useCallback on ImageDecode components for React and Next
1 parent 9c2c3ba commit a31e908

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

hello-world/next/components/ImageCapture/ImageCapture.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function ImageCapture() {
1111
let pCvRouter: MutableRefObject<Promise<CaptureVisionRouter> | null> = useRef(null);
1212
let isDestroyed = useRef(false);
1313

14-
const decodeImg = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => {
14+
const decodeImg = async (e: React.ChangeEvent<HTMLInputElement>) => {
1515
let files = [...(e.target.files as any as File[])];
1616
e.target.value = ""; // reset input
1717
resultsContainer.current!.innerText = "";
@@ -46,7 +46,7 @@ function ImageCapture() {
4646
console.error(errMsg);
4747
alert(errMsg);
4848
}
49-
}, []);
49+
};
5050

5151
useEffect((): any => {
5252
// In 'development', React runs setup and cleanup one extra time before the actual setup in Strict Mode.

hello-world/react-hooks/src/components/ImageCapture/ImageCapture.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useEffect, MutableRefObject, useCallback } from "react";
1+
import React, { useRef, useEffect, MutableRefObject } from "react";
22
import "../../dynamsoft.config"; // import side effects. The license, engineResourcePath, so on.
33
import { EnumCapturedResultItemType } from "dynamsoft-core";
44
import { BarcodeResultItem } from "dynamsoft-barcode-reader";
@@ -11,7 +11,7 @@ function ImageCapture() {
1111
let pCvRouter: MutableRefObject<Promise<CaptureVisionRouter> | null> = useRef(null);
1212
let isDestroyed = useRef(false);
1313

14-
const captureImage = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => {
14+
const captureImage = async (e: React.ChangeEvent<HTMLInputElement>) => {
1515
let files = [...(e.target.files as any as File[])];
1616
e.target.value = ""; // reset input
1717
resultsContainer.current!.innerText = "";
@@ -46,7 +46,7 @@ function ImageCapture() {
4646
console.error(errMsg);
4747
alert(errMsg);
4848
}
49-
}, []);
49+
};
5050

5151
useEffect((): any => {
5252
// In 'development', React runs setup and cleanup one extra time before the actual setup in Strict Mode.
@@ -56,9 +56,11 @@ function ImageCapture() {
5656
return () => {
5757
isDestroyed.current = true;
5858
if (pCvRouter.current) {
59-
pCvRouter.current.then((cvRouter) => {
60-
cvRouter.dispose();
61-
}).catch((_) => { })
59+
pCvRouter.current
60+
.then((cvRouter) => {
61+
cvRouter.dispose();
62+
})
63+
.catch((_) => {});
6264
}
6365
};
6466
}, []);

0 commit comments

Comments
 (0)