How to get a notifications list by feed on react app
Hello Team!, So i have 2 feed identifier
market
and trigger
and i use 2 different useFetchNotification
hook to fetch the notifications with 2 different feed identifier but somehow the data got replaced by one and another its either market
or trigger
, market
feed is used for the entirety of the app and i want to use novu socket by trigger
feed to get update to trigger api call![No description](https://answer-overflow-discord-attachments.s3.us-east-1.amazonaws.com/1256182270050570240/image.png)
15 Replies
@Jauhari, you just advanced to level 2!
Hi @Jauhari, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question.
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* API Reference
* React Get Started
* How to send push notifications in an Android app (react native) with FCM and Novu
* Customizing Notification Center
-----------------------------
Answer
Based on the information provided in the documentation sources, I can offer some guidance on how to handle multiple feeds in a React app using Novu. Let's break this down step by step:
1. Using multiple feeds:
The Novu React library supports configuring multiple feeds (or stores) for different notification types (1) . You can define these stores in the
NovuProvider
component .
2. Fetching notifications for different feeds:
You're correct in using the useFetchNotifications
hook to fetch notifications for different feeds. However, the issue you're experiencing where data is being replaced might be related to how you're managing the state for these different feeds (2) .
To fetch notifications for a specific feed, you can use the useFetchNotifications
hook like this:
3. Using sockets for real-time updates:
For real-time updates, you can use the useSocket
hook provided by Novu (3) . Here's an example of how you might use it:
However, it's important to note that there have been some reported issues with handling multiple feeds simultaneously (4) . Some users have experienced intermittent failures to load when visiting multiple feeds at the same time. A workaround suggested is to avoid nesting providers component-wise .
Given the complexity of your use case and the potential issues with multiple feeds, you might want to consider alternative approaches. For instance, you could use a single feed and differentiate notifications using payload data, or you could use topics instead of feeds for organization-wide notifications (5) .
If you're still experiencing issues after trying these approaches, it might be worth clicking on the "Ask for help" button to tag a team member for a more detailed review of your specific implementation.
solution 1 & 2 doenst work still gives me same result
![No description](https://answer-overflow-discord-attachments.s3.us-east-1.amazonaws.com/1256184077942521899/image.png)
Got it. Tagging @Support for additional help.
@Jauhari
Please make sure feedIdentifier value is correct
it is correct
@Jauhari
go to network tab and copy the request as curl and paste it her (hide any sensitive info)
please wait
sorry for the late response it was night over here and my co-worker unable to reached that time, here is the curl
Trigger
Govmart - (before was market)
Thanks
@Jauhari
I could not reproduce the issue on latest version 0.24.0.
Could you please upgrade the self hosted version to 0.24.0 ?
Hey, i already try to upgrade the self host to 0.24.0, and also found this issue.
Here is the branch which are using 0.24.0 version :
https://github.com/yosiawan/novu-playground/tree/chore/novu-new-version-listen-different-feeds
Here is the branch which are using 0.16.0 version :
https://github.com/yosiawan/novu-playground/tree/chore/novu-different-feeds
@Stelli
I think you misunderstood the version upgrade
https://github.com/yosiawan/novu-playground/blob/chore/novu-new-version-listen-different-feeds/package.json#L12
here, you updated
@novu/notification-center
to 0.24.0 version.
I meant to update your self hosted novu instance to 0.24.0i see
let me try to talk to my team, and will update to you later. Thank you @Pawan Jain
after trying to upgrade the novu self hosted instance in local to 0.24.0, the bug is still happening. Do you have any idea ? @Pawan Jain
Hi @Pawan Jain, sorry to suddenly jump in, I managed to reproduce the issue consistently in the local machine.
I upgraded the novu server instance into v0.24.0 as instructed. However, the issue persist as long as i use the react sdk with version 0.16.1 and later.
I managed to narrow down that the root cause exists in the react SDK due to the request being sent. Everytime
useFetchNotifications
hook is being called, an HTTP request is sent to the novu API instance. Works perfectly in 0.15.0 and 0.16.0, however that the behavior doesn't work as expected in react SDK v0.16.1 and higher, it appears that it only send 1 request to the API instance. Screenshots are provided my arguments, ran using the exact same code and exact same server instance, only differs in the SDK version.
My hypothesis is that both function calls use some shared variable that either being locked by the first request or overwritten by the second request![No description](https://answer-overflow-discord-attachments.s3.us-east-1.amazonaws.com/1257995208537276456/image.png)
![No description](https://answer-overflow-discord-attachments.s3.us-east-1.amazonaws.com/1257995208877146152/image.png)
![No description](https://answer-overflow-discord-attachments.s3.us-east-1.amazonaws.com/1257995209170489475/image.png)
Here's the code that I use,
Is there anything I did wrong in the code?
Hello @Support , would you mind checking on the issue? Thank you!