balazssagi/use-fuse

More friendly use with fuse@5.2.3

Opened this issue · 0 comments

The problem is fuse search result add item property wrapper.

// before seach
[
{
    "title": "The DaVinci Code",
    "author": {
      "firstName": "Dan",
      "lastName": "Brown"
    }
  },
]
// after search
[
  {
    "item": {
      "title": "The DaVinci Code",
      "author": {
        "firstName": "Dan",
        "lastName": "Brown"
      }
    },
    "refIndex": 6
  }
]

I recommand that we can extract result with reduce

//...
const results = React.useMemo(() => {
    return fuse.search(searchItem).reduce((acc, curr) => {
      if(curr.item) {
        acc.push(curr.item)
      }
      return acc
    }, [])
  }, [fuse, searchItem])

return results