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(plugins): provide state to transformSource #516

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

francoischalifour
Copy link
Member

Description

When transforming plugin sources, you sometimes need to access the state to conditionally apply some logic. Providing the Autocomplete state to transformSource allow these use cases.

Usage

Example of Query Suggestions hidden when there's no query.

const querySuggestionsPlugin = createQuerySuggestionsPlugin({
  searchClient,
  indexName: 'instant_search_demo_query_suggestions',
  transformSource({ source, state }) {
    if (!state.query) {
      return null;
    }

    return source;
  },
});

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 8, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 303162c:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-query-suggestion-with-categories Configuration
@algolia/autocomplete-example-query-suggestions-with-hits Configuration
@algolia/autocomplete-example-query-suggestions-with-inline-categories Configuration
@algolia/autocomplete-example-query-suggestions-with-recent-searches Configuration
@algolia/autocomplete-example-query-suggestions Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-recently-viewed-items Configuration
@algolia/autocomplete-example-starter Configuration

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seamless

@francoischalifour francoischalifour merged commit eaa2026 into next Apr 8, 2021
@francoischalifour francoischalifour deleted the feat/transformSource-state branch April 8, 2021 09:09
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.

3 participants