Skip to content

Commit 4ce0ec1

Browse files
committed
Cleanup effects
1 parent d3d3142 commit 4ce0ec1

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

packages/expo/src/modules/push/KnockExpoPushNotificationProvider.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ const InternalKnockExpoPushNotificationProvider: React.FC<
211211
customNotificationHandler ?? defaultNotificationHandler,
212212
});
213213

214+
const response = Notifications.getLastNotificationResponse();
215+
if (response?.notification) {
216+
knockClient.log(
217+
"[Knock] Expo Push Notification was interacted with (initial)",
218+
);
219+
updateKnockMessageStatusFromNotification(
220+
response.notification,
221+
"interacted",
222+
);
223+
notificationTappedHandler(response);
224+
}
225+
}, [
226+
customNotificationHandler,
227+
knockClient,
228+
notificationTappedHandler,
229+
updateKnockMessageStatusFromNotification,
230+
]);
231+
232+
useEffect(() => {
214233
if (autoRegister) {
215234
registerForPushNotifications()
216235
.then(() => {
@@ -244,16 +263,6 @@ const InternalKnockExpoPushNotificationProvider: React.FC<
244263
notificationReceivedHandler(notification);
245264
});
246265

247-
const response = Notifications.getLastNotificationResponse();
248-
if (response?.notification) {
249-
knockClient.log("[Knock] Expo Push Notification was interacted with");
250-
updateKnockMessageStatusFromNotification(
251-
response.notification,
252-
"interacted",
253-
);
254-
notificationTappedHandler(response);
255-
}
256-
257266
const notificationResponseSubscription =
258267
Notifications.addNotificationResponseReceivedListener((response) => {
259268
knockClient.log("[Knock] Expo Push Notification was interacted with");
@@ -268,18 +277,16 @@ const InternalKnockExpoPushNotificationProvider: React.FC<
268277
notificationReceivedSubscription.remove();
269278
notificationResponseSubscription.remove();
270279
};
271-
272-
// TODO: Remove when possible and ensure dependency array is correct
273-
// eslint-disable-next-line react-hooks/exhaustive-deps
274280
}, [
275281
registerForPushNotifications,
276282
notificationReceivedHandler,
277283
notificationTappedHandler,
278-
customNotificationHandler,
279284
autoRegister,
280285
expoPushToken,
281286
knockExpoChannelId,
282287
knockClient,
288+
registerPushTokenToChannel,
289+
updateKnockMessageStatusFromNotification,
283290
]);
284291

285292
return (

0 commit comments

Comments
 (0)