usePreferences Hook Ignores Filter

Hi team, I'm using the usePreferences hook from the Novu React Native SDK, and I’ve encountered a couple of issues: 1) Filter Not Applied: When passing filter parameters (e.g., tags: [tag]), the hook still returns all preferences, not just those matching the filter. const { preferences, isLoading } = usePreferences({ filter: { tags: [tag], }, }); 2) Potential Caching Issue: When I open the screen that uses this hook, navigate away, and then return to it, the hook doesn't seem to re-run. It returns undefined, and isLoading is false. This feels like some stale cache is being returned, and the hook is not refetching fresh data. Let me know if this is expected behavior or if there's a recommended workaround. Otherwise, it might be worth treating this as a bug. Thanks in advance!
8 Replies
Pawan Jain
Pawan Jain2mo ago
Hi Yurii

usePreferences hook returns a refetch function. You will need to use that function to refetch the data again
const { preferences, isLoading, isFetching, refetch } = usePreferences({
filter: {
tags: ["events:attend"],
},
});
const { preferences, isLoading, isFetching, refetch } = usePreferences({
filter: {
tags: ["events:attend"],
},
});
yurii_kluban
yurii_klubanOP2mo ago
So, it will resolve the second issue, but still filter not applied. It's the main problem
Pawan Jain
Pawan Jain2mo ago
Checking again from my side @yurii_kluban Its working for me as expected
Pawan Jain
Pawan Jain2mo ago
I have applied filter with tag value events:attend . I have 6 workflows with this tag, and usePreference hook is returning global + 6 workflow preference
yurii_kluban
yurii_klubanOP2mo ago
Here my logs, I do the same as you. One point that is wondering me, I do not see in the request params my attached filters for some reason, but I think I should. Using "@novu/react-native": "3.6.0"
No description
No description
No description
No description
Pawan Jain
Pawan Jain2mo ago
i was testing in @novu/react. Let me quickly check with react native sdk. I thought, it's behaviour will be similar to @novu/react-native
yurii_kluban
yurii_klubanOP2mo ago
please, let me know. The usage so simple, that's why I'm sure I'm doing it in the correct way 😌
Novu_Bot
Novu_Bot2mo ago
@yurii_kluban, you just advanced to level 1!

Did you find this page helpful?