reactjsinput-filteringfuse.js

Filter multiple lists using Fuse js at the same time


I have 3 lists generated via API. I want to filter these lists at the same time using Fuse js. I checked the documentation and could not find the solution for filtering multiple lists.

I don't know how to pass 3 different lists as a parameter to the Fuse method.

this.state = {
  a: [],
  b: [],
  c: [],
}

filterVal = (e) =>{
  let searchOptions = {
    keys:['name'], //name is common key across all 3 lists
    includeMatches: true
  }

  var fuse = new Fuse(a,b,c, searchOptions); //not sure how pass 3 lists here
  var filteredResult = fuse.search(e.target.value); //passed the user input value
}

Solution

  • You can merge list like:

    var fuse = new Fuse([...a, ...b, ...c] , searchOptions)