
Convex Has a Free API You're Not Using
Convex is a reactive backend-as-a-service with real-time sync, ACID transactions, and type-safe queries. Think Firebase but with a real database and TypeScript. The Free APIs You're Missing 1. Reactive Queries — Automatic Real-Time // convex/messages.ts import { query } from " ./_generated/server " ; import { v } from " convex/values " ; export const list = query ({ args : { channelId : v . id ( " channels " ) }, handler : async ( ctx , args ) => { return await ctx . db . query ( " messages " ) . withIndex ( " by_channel " , q => q . eq ( " channelId " , args . channelId )) . order ( " desc " ) . take ( 50 ); }, }); // React component — AUTOMATICALLY re-renders when data changes function Chat ({ channelId }) { const messages = useQuery ( api . messages . list , { channelId }); return messages ?. map ( m => < Message key = { m . _id } message = { m } /> ) ; } 2. Mutations — ACID Transactions export const send = mutation ({ args : { channelId : v . id ( " channels " ), text : v . string
Continue reading on Dev.to Webdev
Opens in a new tab


