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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-filter-search

v1.1.11

Published

React Filter Search is a React component for filtering client-side data rendered to your UI.

Downloads

1,037

Readme

React Filter Search 🔍

Travis npm package Coveralls

This is a small, unobtrusive React component for filtering client-side application data.

Installation

npm i react-filter-search

yarn add react-filter-search

Usage

React Filter Search is simply a component that requires data in application state (needs to be an array of objects and an input value. In turn, you'll get back...

  • filtered data based on user input
  • all data in absence of any search input

This data flows back up in the form of renderResults, which is a render prop that returns one of the above. So you'll be responsible for setting up passing in data and an input value.

In this way, React Filter Search is unopinionated about how you store your data and how you handle user input in your application. 🎉

//
/*-Other Imports-*/
//
import FilterResults from 'react-filter-search';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: [],
      value: ''
    };
  }
  componentWillMount() {
    fetch('https://jsonplaceholder.typicode.com/users')
      .then(response => response.json())
      .then(json => this.setState({ data: json }));
  }
  handleChange = event => {
    const { value } = event.target;
    this.setState({ value });
  };
  render() {
    const { data, value } = this.state;
    return (
      <div>
        <input type="text" value={value} onChange={this.handleChange} />
        <SearchResults
          value={value}
          data={data}
          renderResults={results => (
            <div>
              {results.map(el => (
                <div>
                  <span>{el.name}</span>
                  <span>{el.email}</span>
                </div>
              ))}
            </div>
          )}
        />
      </div>
    );
  }
}

The magic 🧙happens in renderResults, which returns an array of objects. Your data has either been filtered based on user input, or not.

Filtering logic will iterate over any level of nesting in your data structure. Which means a good suggestion for this is something like user data or todo items that aren't heavily nested at many levels.

If you wish to filter only using certain attributes then you can use the optional pick prop.

// if each object is of the form
var obj = { name: "Leanne Graham", username: "Bret", email: "[email protected]", company: {"name": "Romaguera-Crona"} }
<SearchResults
  ...
  pick={['username', 'company.name']}
  ...
/>
// your objects will be filtered only with the name and company.name fields
// but you can still render other values like username and email

To render your data, simply use .map() to render to the view--the data retains in the same structure. Return some inline JSX, or feed each element into a stateless React component that renders some UI.

props

| name | type | required?| | ---------------- |----------------------| ---------| | value | string | true |
| data | array of objects | true | | reunderResults | func | true | | pick | array of strings | false |

Contributions

Read CONTRIBUTING.md and join the fun! 🎉