npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

handy-filter-hook

v1.0.3

Published

Handy Filter Hook is a react hook for Handy Filter

Readme

Handy Filter Hook GitHub license npm version

Overview

Handy Filter Hook is a react hook for Handy Filter.

Installation

npm:

npm install handy-filter handy-filter-hook

yarn:

yarn add handy-filter handy-filter-hook

Peer Dependencies

Handy Filter Hook does not depend on the specific version of react or handy-filter. You only need to install them.

NOTE: The minimum supported version of handy-filter is 1.0.9

Table of Contents

Usage

Handy Filter Hook is fully compatible with handy-filter conditions.

import React from 'react';
import { eq } from 'handy-filter';
import useFilter from 'handy-filter-hook';

const MyComponent = (data) => {
  const [filteredData, setCondition] = useFilter({ init: data });
  
  const onChangeHandler = (newValue) => {
    setCondition(eq('nesded.someProp', newValue));
  };

  return <SomeComponent values={filteredData} onChange={onChangeHandler}/>;
};

With async data

If you receive data asynchronously you can use the third function that is returned from useFilter to set the received data:

import React, { useEffect } from 'react';
import { ne } from 'handy-filter';
import useFilter from 'handy-filter-hook';

const MyComponent = () => {
  const [filteredData, setCondition, setData] = useFilter();
  
  const onChangeHandler = (newValue) => {
    setCondition(ne('nesded.someProp', newValue));
  };

  useEffect(() => {
    const getData = async () => {
      const data = await myFetch();
      setData(data);
    };
  });

  return <SomeComponent values={filteredData} onChange={onChangeHandler}/>;
};

NOTE: the setCondition and setData are stable and won’t change on re-renders.

Multiple conditions

If you want to set multiple conditions, for example when you have more than one component that change your data, you need to use a key as the second parameter of setCondition:

import React, { useEffect } from 'react';
import { icnt, eq } from 'handy-filter';
import useFilter from 'handy-filter-hook';

const MyComponent = (data) => {
  const [filteredData, setCondition] = useFilter({ init: data });
  
  const onChangeHandler = (newValue) => {
    setCondition(icnt('nesded.someProp', newValue), 'foo');
  };

  const onClickHandler = (newValue) => {
    setCondition(eq('prop', newValue), 'bar');
  };

  return (
    <>
      <Foo onChange={onChangeHandler}/>
      <Bar onClick={onClickHandler}/>
      <DataViewer data={filteredData}/>
    </>
  );
};

The key can be any value you want, all you need is for the key to be unique within one component.

By default, conditions with different keys are joined with logical "and". If you want to change this behavior see hook options.

Hook options

If you want to change the default hook behavior, you need to pass options object to useFilter:

useFilter({ options: yourOptions })

join

Sets how the conditions with different keys will be joined.

|Valid values|Default| |:----------:|:-----:| | and, or | and |

For example:

import { gte, ne } from 'handy-filter';
import useFilter from 'handy-filter-hook';

const init = [
  { foo: 10, bar: null },
  { foo: 20, bar: true },
  { foo: 50, bar: null },
  { foo: 100, bar: false },
  { foo: 5, bar: true },
];

const [filteredData, setCondition] = useFilter({ init, options: { join: /* 'and' or 'or' */ } });

setCondition(gte('foo', 20), 'key1');
setCondition(ne('bar', null), 'key2');

// if the join option is 'and' result will be
// [{ foo: 20, bar: true }, { foo: 100, bar: false }]

// if the join option is 'or' result will be
// [{ foo: 20, bar: true }, { foo: 50, bar: null }, { foo: 100, bar: false }, { foo: 5, bar: true }]