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(core): provide previous state to onStateChange #335

Merged
merged 3 commits into from Oct 12, 2020
Merged

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Oct 8, 2020

Summary

This PR adds a new prop prevState to onStateChange.
With this addition, users don't have to keep track of the previous state for comparison.

For example,

      onStateChange({ state }) {
        if (state.query !== queryRef.current) {
          queryRef.current = state.query;
          props.refine(state.query);
        }
      },

becomes

      onStateChange({ state, prevState }) {
        if (state.query !== prevState.query) {
          props.refine(state.query);
        }
      },

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 8, 2020

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 4075aab:

Sandbox Source
algolia/autocomplete.js: js Configuration

@francoischalifour francoischalifour changed the title feat(onStateChange): provide prevState feat(core): provide previous state to onStateChange Oct 10, 2020
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.

only a shallow copy, but since there's no other mutations, that should be all right

@eunjae-lee eunjae-lee merged commit 21739b4 into next Oct 12, 2020
@francoischalifour francoischalifour deleted the feat/prev-state branch October 12, 2020 15:03
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.

None yet

3 participants