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:

Copy
Copied
... 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.

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

Arguments

Argument Type Required? Description
options Options true Required options object

Options

Option Type Required? Description
filter BooleanFilter true The BooleanFilter you would like to act on

Result

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

Example

Copy
Copied
function BooleanFilter({ filter }) {
  const { apply } = useBooleanFilter({ filter });
  return (
    <Checkbox
      label={filter.name}
      checked={filter.value}
      onChange={(e) => {
        apply({ value: e.currentTarget.checked });
      }}
    />
  );
}
Copyright © Norce 2023. All right reserved.