Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove store parameter #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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.

1 participant