# react-filter-element

> use this package to easily filter out html elements in react

Latest version **1.0.4** (published 2022-05-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-filter-element
pnpm add react-filter-element
yarn add react-filter-element
bun add react-filter-element
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-05-28 |
| First published | 2022-05-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | MD Ripon Islam |
| Maintainers | ripon876 |
| Keywords | filter, react-filter, filter, html |

## Links

- npm: https://www.npmjs.com/package/react-filter-element
- Repository: https://github.com/Ripon876/react-filter-element
- Homepage: https://github.com/Ripon876/react-filter-element#readme
- Issues: https://github.com/Ripon876/react-filter-element/issues
- npm.io page: https://npm.io/package/react-filter-element

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2022-05-28
- 1.0.3 — 2022-05-28
- 1.0.2 — 2022-05-28
- 1.0.1 — 2022-05-28
- 1.0.0 — 2022-05-28

## README

# React Filter Element




> Use this hook to easily filter out your html element within a parent element.

Installation
                    
> `$ npm i react-filter-element`

###### Using ->

###### Import the module


Import `useFilterElement ` hook from the module

```javascript
import React from 'react';
import useFilterElement from 'react-filter-element';
```

You also need to import `useRef` hook from react to target the parent element

```javascript
import React,{useRef} from 'react';
import useFilterElement from 'react-filter-element';
```

Next you need to use the `useRef` hook  to target the element and pass the element when calling the `useFilterElement` hook

```javascript
const parent = useRef(null);
const [filter,items] = useFilterElement(parent); // calling the hook with the parent
 

<div  ref={parent}></div> // html
```
you will get back `filter` and `items` from the hook. ` filter` refers to the main function to use the filter and ` items`  contains the childs 

Now call the function with a key name as argument and  set the key name as a class of the childs ( you can also pass `*` as  key , it will show every child)

```html
<button  onClick={() => filter('bird')}>Birds</button>
<button  onClick={() => filter('fish')}>Fish</button>
	
<div className="bird">
		<h1>Bird</h1>
</div>
<div className="fish">
		<h1>Fish</h1>
</div>
```
	


full sample code


```javascript
import React,{useRef} from 'react';
import useFilterElement from 'react-filter-element';

const parent = useRef(null);
const [filter,items] = useFilterElement(parent); // calling the hook with the parent


// html

	<button  onClick={() => filter('bird')}>Birds</button>
	<button  onClick={() => filter('fish')}>Fish</button>
	
<div  ref={parent}> 
		<div className="bird">
			<h1>Bird</h1>
		</div>
		<div className="fish">
			<h1>Fish</h1>
		</div>
</div>
```
  Live working demo [here](https://react-filter-element.netlify.app/ "here")

---
_Source: https://npm.io/package/react-filter-element · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
