React query builder
MIT · React 18+ · SSR-safe · TypeScript
@qnot/react, default builder, live on this page. Edit a rule and watch the exports.
pnpm add @qnot/core @qnot/reactA React query builder in two files.
The default <QueryBuilder> is unstyled HTML with a small stylesheet. For more control, create the store with useQueryStore, share it with <QueryProvider>, and read it from anywhere with useQuery, useHistory or useIsValid. Each rule component subscribes to its own node through useRule(id), so a keystroke re-renders one rule, not the tree.
Prefer a designed UI? The coss ui, shadcn/ui and MUI builders are React components built on these hooks.
What you get.
- Typed schemadefineFields · QueryOf
Declare fields once. Rule values narrow by field and operator, and validated queries come back typed.
- Export anywhereSQL · Mongo · JsonLogic
Parameterized SQL in five dialects, MongoDB, JsonLogic, Elasticsearch, SpEL and plain English.
- Validationissues
Per-rule issues from the schema: required, min/max, patterns, options and your own checks.
- Undo and redohistory
Every edit is a step, typing merges into one. The demo above has the buttons wired up.
- Drag and dropdnd
Move rules and groups anywhere. The React binding ships the drag handle and drop target helpers.
- Any languagelabels · messages
Every UI string and validation message is an override away. No i18n library required.
- Same query on the servervalidate · compile
Share fields.ts with your API. Validate the query, then run it as bound SQL or filter rows in memory.
- Fast at 1,000 rulesper-node subscriptions
Editing one rule updates one rule. A keystroke costs the same at ten rules or a thousand.
How it compares.
Questions people ask
- Is it free?
- Yes. qnot is MIT licensed, the core and every binding. There is no paid tier, no license key and no API key.
- Does it work with Next.js and server rendering?
- Yes. Render the builder from a client component ('use client'). It server-renders too: the hooks give React the same snapshot on the server, and node ids are sequential per store, so the server HTML matches the client. Your route handlers can import the same fields.ts to validate and run the query.Server usage
- Which React versions are supported?
- React 18 and later. The hooks are built on useSyncExternalStore.
- How is it different from react-querybuilder?
- react-querybuilder is older, more widely used, has React Native support and exports to more formats. qnot types rule values by field and operator, runs outside React too, and keeps keystrokes under a millisecond at 1,000 rules where react-querybuilder takes about 57 ms in our benchmark.qnot vs react-querybuilder
- Can I keep my saved react-querybuilder or RAQB queries?
- Yes. Give the store format: rqb or format: raqb and value / onChange read and write that library's JSON, so stored queries load as they are and keep being saved in the same shape.Migration guide
- Can I use my own components or UI kit?
- Yes. Swap any piece of the default builder through the components prop, or build your own from the hooks (useGroup, useRule, useNode). Ready-made builders for coss ui, shadcn/ui and MUI install as source with one shadcn command.shadcn/ui builder Custom UI guide