Skip to content

Store all notifications received in array with useState #1

@kabeza

Description

@kabeza

Hi

I was wondering if you could provide with some example code about how to store all the notifications received from FCM in a useState (array). All the examples I see on github or Google handle notifications in one main useEffect, which is executed once only

useEffect(() => {
  // req user permission
  // get token
  // block of code that is executed each time notif. arrives
  const unsubscribe = messaging().onMessage(async remoteMessage => {
    // save notification
  });
  return () => unsubscribe();
}, []);

Therefore I cannot store the notifications somewhere, for example

const [notifications, setNotifications] = useState<NotificationType[]>([]);

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions