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(js): provide setters and refresh to render API #598

Merged
merged 2 commits into from
May 31, 2021

Conversation

francoischalifour
Copy link
Member

Description

This forwards the scoped API (setters and refresh) to the render param to allow complex UIs.

This is useful when you want to interact with the Autocomplete lifecycle from the global render hook, with a preview panel for instance.

Usage

autocomplete({
  // ...
  render({ elements, setQuery, refresh }, root) {
    render(
      <PreviewPanel
        elements={elements}
        onItemSelect={(item) => {
          setQuery(item.query);
          refresh();
        }}
      />,
      root
    );
  },
});

This forwards the scoped API (setters and `refresh`) to the `render` param to allow complex UIs.

This is useful when you want to interact with the Autocomplete lifecycle from the global `render` hook, with a preview panel for instance.
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 31, 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 40c149c:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-starter-algolia Configuration
@algolia/autocomplete-example-starter Configuration
@algolia/autocomplete-example-voice-search Configuration
@algolia/autocomplete-example-vue Configuration

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

seems perfectly consistent!

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.

Clean!

packages/autocomplete-js/src/__tests__/render.test.ts Outdated Show resolved Hide resolved
Co-authored-by: Clément Vannicatte <[email protected]>
@francoischalifour francoischalifour merged commit 3e78566 into next May 31, 2021
@francoischalifour francoischalifour deleted the feat/render-scoped-api branch May 31, 2021 11:29
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