Deragon
Deragon
CCConvex Community
Created by Deragon on 2/27/2025 in #support-community
Convex useQuery Not Updating in Real-Time
Convex useQuery Not Updating in Real-Time I'm building an npm package (xerexjs) for real-time notifications in React/Next.js using Convex. The useQuery for fetching notifications requires a manual refresh instead of updating in real-time. Schema
export default defineSchema({
members: defineTable({
developerUserId: v.string(),
notifications: v.optional(v.array(v.id("notifications"))),
}),

notifications: defineTable({
content: v.string(),
buttonText: v.string(),
buttonUrl: v.string(),
recipients: v.array(v.id("members")),
}).index("by_recipient", ["recipients"]),
});
export default defineSchema({
members: defineTable({
developerUserId: v.string(),
notifications: v.optional(v.array(v.id("notifications"))),
}),

notifications: defineTable({
content: v.string(),
buttonText: v.string(),
buttonUrl: v.string(),
recipients: v.array(v.id("members")),
}).index("by_recipient", ["recipients"]),
});
Query Function
export const getAllNotifications = query({
args: { userId: v.id("members") },
handler: async (ctx, args) => {
return await ctx.db
.query("notifications")
.filter((q) => q.field("recipients").contains(args.userId))
.order("desc")
.collect();
},
});
export const getAllNotifications = query({
args: { userId: v.id("members") },
handler: async (ctx, args) => {
return await ctx.db
.query("notifications")
.filter((q) => q.field("recipients").contains(args.userId))
.order("desc")
.collect();
},
});
Client-Side Usage
const notifications = useQuery(api.notification.getAllNotifications, { userId });
const notifications = useQuery(api.notification.getAllNotifications, { userId });
Issue - New notifications don't appear in real-time; they require a refresh. - console.log(notifications) inside useEffect only updates on refresh. Troubleshooting Steps Tried - Restarting the dev server - Clearing cache - Checking Convex version (v1.19.2) Question Am I missing something to trigger real-time updates?
5 replies