|
@@ -44,7 +44,7 @@ function MyScreen(props) {
|
44
|
44
|
}
|
45
|
45
|
};
|
46
|
46
|
// Register the listener to all events related to our component
|
47
|
|
- const unsubscribe = Navigation.events().bindComponent(listener, props.componentId);
|
|
47
|
+ const unsubscribe = Navigation.events().registerComponentListener(listener, props.componentId);
|
48
|
48
|
return () => {
|
49
|
49
|
// Make sure to unregister the listener during cleanup
|
50
|
50
|
unsubscribe.remove();
|
|
@@ -59,7 +59,7 @@ function MyScreen(props) {
|
59
|
59
|
}
|
60
|
60
|
```
|
61
|
61
|
|
62
|
|
-Notice that in the example above, we call `Navigation.events().bindComponent()` to register our listener even though we're not binding any component. That's because our listener is registered with the `componentId` passed in the second argument.
|
|
62
|
+In the example above, our listener is registered with the `componentId` passed in the second argument, and will receive only its related events.
|
63
|
63
|
|
64
|
64
|
:::tip
|
65
|
65
|
[underscopeio/react-native-navigation-hooks](https://github.com/underscopeio/react-native-navigation-hooks) is a wonderful library which greatly simplifies usage with hooks by introducing dedicated hooks for each event. The following example, which is taken from their docs, shows how to listen to all appear events and a particular screen's appear events:
|
|
@@ -85,4 +85,4 @@ const ScreenComponent = ({ componentId }) => {
|
85
|
85
|
)
|
86
|
86
|
}
|
87
|
87
|
```
|
88
|
|
-:::
|
|
88
|
+:::
|