Skip to content

Commit 0ff2161

Browse files
authored
docs: unsubscribe even listeners on unmount (#340)
1 parent b85827c commit 0ff2161

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ export const App = () => {
169169
const [permissions, setPermissions] = useState({});
170170

171171
useEffect(() => {
172-
PushNotificationIOS.addEventListener('notification', onRemoteNotification);
172+
const type = 'notification';
173+
PushNotificationIOS.addEventListener(type, onRemoteNotification);
174+
return () => {
175+
PushNotificationIOS.removeEventListener(type);
176+
};
173177
});
174178

175179
const onRemoteNotification = (notification) => {
@@ -216,7 +220,11 @@ export const App = () => {
216220
};
217221

218222
useEffect(() => {
219-
PushNotificationIOS.addEventListener('notification', onRemoteNotification);
223+
const type = 'notification';
224+
PushNotificationIOS.addEventListener(type, onRemoteNotification);
225+
return () => {
226+
PushNotificationIOS.removeEventListener(type);
227+
};
220228
});
221229

222230
const onRemoteNotification = (notification) => {
@@ -234,9 +242,10 @@ export const App = () => {
234242
};
235243
};
236244
```
245+
237246
## How to recieve rich notification in remote
238247

239-
Follow these [article](https://firebase.google.com/docs/cloud-messaging/ios/send-image) to create rich notification for your own
248+
Follow this [article](https://firebase.google.com/docs/cloud-messaging/ios/send-image) to create rich notification of your own
240249

241250
# Reference
242251

@@ -295,7 +304,7 @@ details is an object containing:
295304
- `isSilent` : If true, the notification will appear without sound (optional).
296305
- `category` : The category of this notification, required for actionable notifications (optional).
297306
- `userInfo` : An object containing additional notification data (optional).
298-
- `image` : It's useful if you need to diplay rich notification (optional).
307+
- `image` : It's useful if you need to diplay rich notification (optional).
299308
- `applicationIconBadgeNumber` The number to display as the app's icon badge. Setting the number to 0 removes the icon badge (optional).
300309
- `repeatInterval` : The interval to repeat as a string. Possible values: `minute`, `hour`, `day`, `week`, `month`, `year` (optional).
301310

@@ -412,8 +421,8 @@ Removes the specified pending notifications from Notification Center
412421

413422
**Parameters:**
414423

415-
| Name | Type | Required | Description |
416-
| ----------- | ----- | -------- | ---------------------------------- |
424+
| Name | Type | Required | Description |
425+
| ----------- | -------- | -------- | ---------------------------------- |
417426
| identifiers | string[] | Yes | Array of notification identifiers. |
418427

419428
---
@@ -473,8 +482,8 @@ Removes the specified delivered notifications from Notification Center
473482

474483
**Parameters:**
475484

476-
| Name | Type | Required | Description |
477-
| ----------- | ----- | -------- | ---------------------------------- |
485+
| Name | Type | Required | Description |
486+
| ----------- | -------- | -------- | ---------------------------------- |
478487
| identifiers | string[] | Yes | Array of notification identifiers. |
479488

480489
---

0 commit comments

Comments
 (0)