Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
holi-frontends
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
app
holi-frontends
Commits
1246682d
Commit
1246682d
authored
1 month ago
by
Malte Finsterwalder
Browse files
Options
Downloads
Patches
Plain Diff
HOLI-10936 fix: wrap track function in useCallback to prevent infinite rerender
parent
5019fdfb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/tracking/hooks/useTracking.ts
+20
-16
20 additions, 16 deletions
core/tracking/hooks/useTracking.ts
with
20 additions
and
16 deletions
core/tracking/hooks/useTracking.ts
+
20
−
16
View file @
1246682d
...
...
@@ -3,6 +3,7 @@ import { usePosthogCrossPlatform } from '@holi/core/tracking/PosthogCrossPlatfor
import
{
useConsentState
}
from
'
@holi/core/tracking/TrackingInitializer
'
import
{
TrackingEvent
}
from
'
@holi/core/tracking/events
'
import
{
ConsentState
,
TrackingHook
}
from
'
@holi/core/tracking/types
'
import
{
useCallback
}
from
'
react
'
const
logger
=
getLogger
(
'
Tracking
'
)
...
...
@@ -10,22 +11,25 @@ const useTracking = (): TrackingHook => {
const
posthog
=
usePosthogCrossPlatform
()
const
[
consent
]
=
useConsentState
()
return
{
track
:
(
event
:
TrackingEvent
)
=>
{
logger
.
debug
(
'
trackEvent
'
,
`tracking "
${
event
.
name
}
" event`
,
event
)
try
{
posthog
.
capture
(
event
.
name
,
{
...
event
.
properties
,
...
ConsentState
.
toEventProperties
(
consent
),
event_version__major
:
event
.
event_version__major
,
event_version__minor
:
event
.
event_version__minor
,
event_version__patch
:
event
.
event_version__patch
,
})
}
catch
(
e
)
{
// console.error will be picked up by Sentry, so this does not go unnoticed to the programmer, but to the user.
// eslint-disable-next-line no-console
console
.
error
(
'
Error during evaluation of onTrack callback
'
,
e
)
}
},
track
:
useCallback
(
(
event
:
TrackingEvent
)
=>
{
logger
.
debug
(
'
trackEvent
'
,
`tracking "
${
event
.
name
}
" event`
,
event
)
try
{
posthog
.
capture
(
event
.
name
,
{
...
event
.
properties
,
...
ConsentState
.
toEventProperties
(
consent
),
event_version__major
:
event
.
event_version__major
,
event_version__minor
:
event
.
event_version__minor
,
event_version__patch
:
event
.
event_version__patch
,
})
}
catch
(
e
)
{
// console.error will be picked up by Sentry, so this does not go unnoticed to the programmer, but to the user.
// eslint-disable-next-line no-console
console
.
error
(
'
Error during evaluation of onTrack callback
'
,
e
)
}
},
[
consent
,
posthog
]
),
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment