Skip to content

Conversation

@angeloashmore
Copy link
Owner

@angeloashmore angeloashmore commented Mar 26, 2019

BREAKING CHANGE: store parameter has been removed. Map results in your component if necessary.

Reasoning

Some indexes are configured to return just an ID as a result. This requires you to map the ID to your data.

Some indexes are configured to return the whole document as a result. This does not require you to map any data.

The hook previously would handle mapping for you, but doing so removed the ability to configure your FlexSearch index to return the whole document by default. This PR removes the store functionality altogether and leaves it up to the user to map the results if necessary.

Upgrade Path

If you relied on the store mapping functionality, map the results in your component:

import React, { useMemo } from 'react'
import { useFlexSearch } from 'react-use-flexsearch'

const Search = (query, index, store) => {
  const results = useFlexSearch(query, index)
  const mappedResults = useMemo(() => results.map(result => store[result]), [results])

  return (
    <ul>
      {mappedResults.map(result => (
        <li key={result.id}>{result.myField}</li>
      )}
    </ul>
  )
}

BREAKING CHANGE: `store` parameter has been removed. Map results in your
component if necessary.
@angeloashmore
Copy link
Owner Author

See #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants