@frontlinetech/react-querybuilder
v9.0.0
Published
The React <QueryBuilder /> component for constructing queries
Downloads
63
Maintainers
Readme
react-querybuilder
The Query Builder component for React
Basic usage
npm install react-querybuilder --save
# OR
yarn add react-querybuilder
import { useState } from 'react';
import { QueryBuilder, RuleGroupType } from 'react-querybuilder';
import 'react-querybuilder/dist/query-builder.css';
const fields = [
{ 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 },
];
export const App = () => {
const [query, setQuery] = useState<RuleGroupType>({
combinator: 'and',
rules: [],
});
return <QueryBuilder fields={fields} query={query} onQueryChange={q => setQuery(q)} />;
};