From 1f032f538b4ce9f477b92be2da68d50606802c6d Mon Sep 17 00:00:00 2001
From: kwyuan <72662648+joeyscave@users.noreply.github.com>
Date: Tue, 09 Apr 2024 01:43:09 +0000
Subject: [PATCH] feat(analytics): PostHog support (#1072)

---
 docs/advanced/creating components.md |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/docs/advanced/creating components.md b/docs/advanced/creating components.md
index 1496b15..27369ab 100644
--- a/docs/advanced/creating components.md
+++ b/docs/advanced/creating components.md
@@ -156,12 +156,13 @@
   // do page specific logic here
   // e.g. attach event listeners
   const toggleSwitch = document.querySelector("#switch") as HTMLInputElement
-  toggleSwitch.removeEventListener("change", switchTheme)
   toggleSwitch.addEventListener("change", switchTheme)
+  window.addCleanup(() => toggleSwitch.removeEventListener("change", switchTheme))
 })
 ```
 
-It is best practice to also unmount any existing event handlers to prevent memory leaks.
+It is best practice to track any event handlers via `window.addCleanup` to prevent memory leaks.
+This will get called on page navigation.
 
 #### Importing Code
 

--
Gitblit v1.10.0