I have a piece of code where I use it almost in all my components and is working perfectly fine but I would like to make it reusable.
I tried to export it in a different file then imported and pass the arguments on the function but it didn't work.
The searchTerm is simply an input where I set the state to the value of the input.
const data = [
{
name: "User"
email: "user@email.com"
phone: 0000000
gender: "male"
notes: "some notes"
birthday: "00/00/0000"
}
]
What I have and want to reuse:
let filteredData = []
if (clients.length > 0) {
filteredData =
data.filter(d=> Object.values(d).join('
').toLowerCase().match(searchTerm.toLowerCase()))
}
What I tried:
export function tableFilter(data, searchTerm) {
if (data.length > 0) {
return data.filter(d => Object.values(d).join('
').toLowerCase().match(searchTerm.toLowerCase()))
}
}
The expected result's are to use the function in all my components without rewriting it. What I am getting now is no data at all.