Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 8464d92

Browse files
authored
fix: memoize return value of useBaseTrigger (#39)
1 parent aa84374 commit 8464d92

3 files changed

Lines changed: 25 additions & 20 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@testing-library/react-hooks": "^3.2.1",
3131
"@types/jest": "^26.0.15",
3232
"@types/react": "^17.0.0",
33+
"@types/react-dom": "^17.0.0",
3334
"cz-conventional-changelog": "3.3.0",
3435
"jest": "^26.6.3",
3536
"react": "^17.0.1",

src/hooks/useBaseTrigger/useBaseTrigger.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@ const useBaseTrigger = (event: Events) => {
2323
TrackingContext
2424
);
2525

26-
return ({ component, label, customParameters }: Dispatch) =>
27-
dispatch &&
28-
dispatch({
29-
app,
30-
view,
31-
elementTree,
32-
event,
33-
component,
34-
label,
35-
timestamp: Date.now(),
36-
customParameters
37-
});
26+
const handleTrigger = React.useCallback(
27+
({ component, label, customParameters }: Dispatch) =>
28+
dispatch &&
29+
dispatch({
30+
app,
31+
view,
32+
elementTree,
33+
event,
34+
component,
35+
label,
36+
timestamp: Date.now(),
37+
customParameters
38+
}),
39+
[app, dispatch, elementTree, event, view]
40+
);
41+
42+
return handleTrigger;
3843
};
3944

4045
export default useBaseTrigger;

yarn.lock

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,13 @@
12441244
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
12451245
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
12461246

1247+
"@types/react-dom@^17.0.0":
1248+
version "17.0.0"
1249+
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.0.tgz#b3b691eb956c4b3401777ee67b900cb28415d95a"
1250+
integrity sha512-lUqY7OlkF/RbNtD5nIq7ot8NquXrdFrjSOR6+w9a9RFQevGi1oZO1dcJbXMeONAPKtZ2UrZOEJ5UOCVsxbLk/g==
1251+
dependencies:
1252+
"@types/react" "*"
1253+
12471254
"@types/react-test-renderer@*":
12481255
version "16.9.3"
12491256
resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.3.tgz#96bab1860904366f4e848b739ba0e2f67bcae87e"
@@ -7034,7 +7041,6 @@ npm@^6.14.8:
70347041
cmd-shim "^3.0.3"
70357042
columnify "~1.5.4"
70367043
config-chain "^1.1.12"
7037-
debuglog "*"
70387044
detect-indent "~5.0.0"
70397045
detect-newline "^2.1.0"
70407046
dezalgo "~1.0.3"
@@ -7049,7 +7055,6 @@ npm@^6.14.8:
70497055
has-unicode "~2.0.1"
70507056
hosted-git-info "^2.8.8"
70517057
iferr "^1.0.2"
7052-
imurmurhash "*"
70537058
infer-owner "^1.0.4"
70547059
inflight "~1.0.6"
70557060
inherits "^2.0.4"
@@ -7068,14 +7073,8 @@ npm@^6.14.8:
70687073
libnpx "^10.2.4"
70697074
lock-verify "^2.1.0"
70707075
lockfile "^1.0.4"
7071-
lodash._baseindexof "*"
70727076
lodash._baseuniq "~4.6.0"
7073-
lodash._bindcallback "*"
7074-
lodash._cacheindexof "*"
7075-
lodash._createcache "*"
7076-
lodash._getnative "*"
70777077
lodash.clonedeep "~4.5.0"
7078-
lodash.restparam "*"
70797078
lodash.union "~4.6.0"
70807079
lodash.uniq "~4.5.0"
70817080
lodash.without "~4.4.0"

0 commit comments

Comments
 (0)