I am trying to redirect to another screen when a notification is received in App.js. I am using useNavigation() but it is not working.
Is there a way to redirect to another screen or use the notifications in another way?
export default function App() {
function UserScreen() {
const navigation = useRef(useNavigation());
navigation.navigate('Chat');
}
useEffect(() => {
const backgroundSubscription = Notifications.addNotificationResponseReceivedListener(
(response) => {
switch (response.request?.content.data.type) {
case 'chat':
return UserScreen()
default:
return console.log('Entro al default')
}
}
);
const foregroundSubscription = Notifications.addNotificationReceivedListener(
(notification) => {
switch (notification.request?.content.data.type) {
case 'chat':
return UserScreen()
default:
return console.log('Entro al default')
}
}
);
return () => {
backgroundSubscription.remove();
foregroundSubscription.remove();
};
}, []);
return (
<Provider store={store}>
<SparkitNavigator />
</Provider>
);
}