onMessage firebase 10.7 it not working ?
Unanswered
American Crocodile posted this in #help-forum
American CrocodileOP
Hi all, i have a problem with onMessage, i can not consolog payload, please help me
useEffect(() => {
console.log('useEffect...');
if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
const messaging = getMessaging(app);
const unsubscribe = onMessage(messaging, (payload) => {
console.log('Foreground push notification received:', payload);
// Handle the received push notification while the app is in the foreground
// You can display a notification or update the UI based on the payload
});
// Cleanup subscription on unmount
return () => {
unsubscribe();
};
}
}, []); // Empty dependency array means this effect runs once on mount and cleanup runs on unmount
useEffect(() => {
console.log('useEffect...');
if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
const messaging = getMessaging(app);
const unsubscribe = onMessage(messaging, (payload) => {
console.log('Foreground push notification received:', payload);
// Handle the received push notification while the app is in the foreground
// You can display a notification or update the UI based on the payload
});
// Cleanup subscription on unmount
return () => {
unsubscribe();
};
}
}, []); // Empty dependency array means this effect runs once on mount and cleanup runs on unmount