Skip to content

Commit 627ff9e

Browse files
committed
fix: use removeEventListener in rnw
1 parent e466345 commit 627ff9e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/DynamicStyleSheet.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ export class DynamicStyleSheet {
8181
if (!canUseDOM) {
8282
debug('unsubscribing from mql');
8383
mql.forEach(mq => mq.unsubscribe());
84+
// @ts-expect-error https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55354
85+
subscription.remove();
86+
} else {
87+
Appearance.removeChangeListener(appearanceListener);
8488
}
85-
86-
// @ts-expect-error https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55354
87-
subscription.remove();
8889
};
8990
}, []);
9091

src/hooks/useDerivedValue.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Dimensions, ScaledSize } from 'react-native';
22
import { useEffect, useRef, useState } from 'react';
3+
import { canUseDOM } from '../utils/utils';
34

45
/**
56
* Use some value derived from dimensions.
@@ -26,8 +27,14 @@ export const useDerivedValue = <T>(func: DerivedFunc<T>): T => {
2627

2728
const subscription = Dimensions.addEventListener('change', listener);
2829

29-
// @ts-expect-error https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55354
30-
return subscription.remove;
30+
return () => {
31+
if (!canUseDOM) {
32+
// @ts-expect-error https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55354
33+
subscription.remove();
34+
} else {
35+
Dimensions.removeEventListener('change', listener);
36+
}
37+
};
3138
}, []);
3239

3340
return valueRef.current;

0 commit comments

Comments
 (0)