@rohitambawata9716/array-method-shortcuts
v1.0.1
Published
This package helps you in saving your time while working on big projects as because of this npm package now you don't need to write that return statement for every array method this would be taken care of by this package.For more details read README.md.
Downloads
1
Maintainers
Readme
array-method-shortcuts
npm i array-method-shortcuts
import {DELETE,universalFilter} from '@rohitambawata9716/array-method-shortcuts'
This file includes two array filter methods:
1. DELETE
method
2. universalFilter
method
1. DELETE
method usage
In short it is a filter method
Theory:
This method is useful in those situations where we want to remove
an item of the array(data provided by database or any data.js file holds an array of objects or simple array) whenever someone clicked
on that item.
Example
: const data = [{id:0,name:'dummy1'},{{id:1,name:'dummy2'}}] etc.
This dummy array holds 2 Objects.
Functional Component:
const [user,setUser] = useState(data)
const clicked
= (id)=>{
setUser(DELETE(user,id))
//use a hook useState
//the above method will only delete the clicked div
}
}
return(){
data
.map((item)=>{
return
(
<div onClick={()=>clicked(item.id)}>
{item.name}
)
})
}
1. universalFilter
method usage
Theory:
This method is useful for universal filtering a given data by providing two arguments.
1.
Data (array)
2.
string of bool condition
Functional Component:
const [user,setUser] = useState(data)
const clicked
= (id)=>{
// Exmp 1
setUser(universalFilter(user,'id !== id'))
//use a hook useState
// Exmp 2
setUser(universalFilter(user,'name === "Rohit" '))
//use a hook useState
//the above method will only delete the clicked div
}
}
return(){
data
.map((item)=>{
return
(
<div onClick={()=>clicked(item.id)}>
{item.name}
)
})
}