
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
react-querybuilder
Advanced tools
React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts
The Query Builder component for React
React Query Builder is a fully customizable query builder component for React, along with a collection of utility functions for importing from, and exporting to, various query languages like SQL, MongoDB, and more.
npm i react-querybuilder
# OR yarn add / pnpm add / bun add
import { useState } from 'react';
import { Field, QueryBuilder, RuleGroupType } from 'react-querybuilder';
import 'react-querybuilder/dist/query-builder.css';
const fields: Field[] = [
{ name: 'firstName', label: 'First Name' },
{ name: 'lastName', label: 'Last Name' },
{ name: 'age', label: 'Age', inputType: 'number' },
{ name: 'address', label: 'Address' },
{ name: 'phone', label: 'Phone' },
{ name: 'email', label: 'Email', validator: ({ value }) => /^[^@]+@[^@]+/.test(value) },
{ name: 'twitter', label: 'Twitter' },
{ name: 'isDev', label: 'Is a Developer?', valueEditorType: 'checkbox', defaultValue: false },
];
const initialQuery: RuleGroupType = {
combinator: 'and',
rules: [],
};
export const App = () => {
const [query, setQuery] = useState(initialQuery);
return <QueryBuilder fields={fields} defaultQuery={query} onQueryChange={setQuery} />;
};
Customizations are not limited to the following libraries, but these have first-class support through their respective compatibility packages:
[!TIP]
To enable drag-and-drop, use
@react-querybuilder/dnd
.For enhanced date/time support, use
@react-querybuilder/datetime
.
To export queries as a SQL WHERE
clause, MongoDB query object, or one of several other formats, use formatQuery
.
const query = {
combinator: 'and',
rules: [
{
field: 'first_name',
operator: 'beginsWith',
value: 'Stev',
},
{
field: 'last_name',
operator: 'in',
value: 'Vai, Vaughan',
},
],
};
formatQuery(query, 'sql');
/*
"(first_name like 'Stev%' and last_name in ('Vai', 'Vaughan'))"
*/
To import queries use parseSQL
, parseMongoDB
, parseJsonLogic
, parseJSONata
, parseCEL
, or parseSpEL
depending on the source.
// Tip: `parseSQL` will accept either a full `SELECT` statement or a `WHERE` clause by itself.
// Everything but the `WHERE` expressions will be ignored.
const query = parseSQL(
`SELECT * FROM my_table WHERE first_name LIKE 'Stev%' AND last_name in ('Vai', 'Vaughan')`
);
console.log(query);
/*
{
"combinator": "and",
"rules": [
{
"field": "first_name",
"operator": "beginsWith",
"value": "Stev",
},
{
"field": "last_name",
"operator": "in",
"value": "Vai, Vaughan",
},
],
}
*/
formatQuery
, transformQuery
, and the parse*
functions can be used without importing from react
(on the server, for example) like this:
import { formatQuery } from 'react-querybuilder/formatQuery';
import { parseCEL } from 'react-querybuilder/parseCEL';
import { parseJSONata } from 'react-querybuilder/parseJSONata';
import { parseJsonLogic } from 'react-querybuilder/parseJsonLogic';
import { parseMongoDB } from 'react-querybuilder/parseMongoDB';
import { parseSpEL } from 'react-querybuilder/parseSpEL';
import { parseSQL } from 'react-querybuilder/parseSQL';
import { transformQuery } from 'react-querybuilder/transformQuery';
(As of version 7, the parse*
functions are only available through these extended exports.)
[v8.8.0] - 2025-07-09
RuleType
property match?: { mode: MatchMode, threshold?: number }
type MatchMode = 'all' | 'some' | 'none' | 'atLeast' | 'atMost' | 'exactly'
operator
will be ignored when match
is present and valid.MatchModeEditor
, which renders when a field is determined to have one or more match modes. The mode selector is the configured valueSelector
and—when a threshold is appropriate—the threshold editor is the configured valueEditor
with inputType: "number"
.getMatchModes
and getSubQueryBuilderProps
to manage these configurations at the top level.Field
properties matchModes
and subproperties
to manage these configurations at the field level.parseJsonLogic
support for "all", "none", and "some" operations.formatQuery
(partial) support for the match
rule property.
preset: "postgresql"
, and only with nested arrays of primitives like strings or numbers.bigIntOnOverflow
. When true, a bigint
will be generated for parsed tokens that represent valid integers outside the safe boundaries of the number
type. (This currently only applies to parseSQL
.)inputType: "bigint"
in all value editors, which will render an input with type="text"
but will store the value as a bigint
if a valid integer is entered.fields
prop processing logic to new useFields
hook.queryBuilder-justified
class to the query builder using the controlClassnames
prop, or to any ancestor element.<label>
elements now have htmlFor
attributes linking their corresponding <input>
elements using an id
generated with useId()
.getValueSources
prop and the Field#valueSources
property can now evaluate to a full option list instead of a simple array of value source strings. This enables translations of the value sources through the label
property.fields
, operators
, combinators
, getOperators
, and getValues
) can now include strings in addition to—or instead of—Option
objects (e.g. ["=", "between"]
). The string itself will be used as both the identifier and label, except in the case of operators and combinators where the default labels will be used if the string matches a value from the default set.parseSQL
maintains precision for large integers by generating a bigint
instead of a number
when necessary.React.Fragment
explicitly instead of the shorthand <>...</>
.preset
option for formatQuery
is one from sqlDialectPresets
, it will only apply if the format
is undefined or one of the SQL-based formats.FAQs
React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts
The npm package react-querybuilder receives a total of 67,926 weekly downloads. As such, react-querybuilder popularity was classified as popular.
We found that react-querybuilder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.