Skip to main content

Boolean Filters

Boolean filters are simple true/false filters.

A boolean filter consists of a name, id, and default value.

A query for boolean filtesr looks like this:

... on BooleanFilter {
id
name
value @client
}

Notice the @client directive on value. This field is added by the Flight framework, and will be updated whenever you use the useBooleanFilter hook.

useBooleanFilter​

useBooleanFilter can be used to update boolean filters. It will update the state of the above client directive, and will also update the URL params. If the boolean filter is active, it will appear in the query string. If inactive, it will not appear in the query string.

const { apply } = useBooleanFilter({ filter });

Arguments​

ArgumentTypeRequired?Description
optionsOptionstrueRequired options object

Options​

OptionTypeRequired?Description
filterBooleanFiltertrueThe BooleanFilter you would like to act on

Result​

PropertyTypeDescription
apply({ value }: { value: boolean }) => Promise<ExecutionResult<BooleanFilter>>Applies the boolean value passed in. Returns a promise that will resolve with the boolean filter.

Example​

function BooleanFilter({ filter }) {
const { apply } = useBooleanFilter({ filter });
return (
<Checkbox
label={filter.name}
checked={filter.value}
onChange={(e) => {
apply({ value: e.currentTarget.checked });
}}
/>
);
}