From 850f895480e8b910a04c37b130bee150ff1efe95 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Thu, 12 Oct 2023 12:40:37 -0700 Subject: [PATCH] Persist the mediaQueryList instance generated by window.matchMedia so that we do actually unbind our previously bound listeners. --- lib/useKResponsiveWindow/MediaQuery.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/useKResponsiveWindow/MediaQuery.js b/lib/useKResponsiveWindow/MediaQuery.js index e919566a8..627bab61b 100644 --- a/lib/useKResponsiveWindow/MediaQuery.js +++ b/lib/useKResponsiveWindow/MediaQuery.js @@ -10,13 +10,17 @@ export default class MediaQuery { constructor(query, eventHandler) { this.query = query; this.eventHandler = eventHandler; + this._mediaQueryList = null; } /** * @returns {Object} Media query list */ get mediaQueryList() { - return window.matchMedia(this.query); + if (!this._mediaQueryList) { + this._mediaQueryList = window.matchMedia(this.query); + } + return this._mediaQueryList; } /**