Skip to content

Commit 8c21b11

Browse files
Memoizing a function. (#30)
* Update index.tsx * Memoizing the component
1 parent 90ef909 commit 8c21b11

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RWebShareProps } from "./interfaces";
2-
import React, { cloneElement, useMemo } from "react";
2+
import React, { cloneElement, useMemo, useCallback, memo } from "react";
33

44
import Backdrop from "./components/backdrop";
55
import iconList from "./components/icon/list";
@@ -9,7 +9,7 @@ import useDisclosure from "./hooks/use-disclosure";
99

1010
const defaultSites = Object.keys(iconList).slice(0, 8);
1111

12-
export const RWebShare = ({
12+
export const RWebShare = memo(({
1313
children,
1414
closeText,
1515
data,
@@ -28,7 +28,7 @@ export const RWebShare = ({
2828
[data]
2929
);
3030

31-
const handleOnClick = async () => {
31+
const handleOnClick = useCallback(async () => {
3232
if (window.navigator.share) {
3333
try {
3434
await window.navigator.share(shareData);
@@ -39,7 +39,7 @@ export const RWebShare = ({
3939
} else {
4040
onOpen();
4141
}
42-
};
42+
}, [shareData])
4343

4444
return (
4545
<>
@@ -62,4 +62,4 @@ export const RWebShare = ({
6262
)}
6363
</>
6464
);
65-
};
65+
});

0 commit comments

Comments
 (0)