diff --git a/packages/react-instantsearch/src/core/InstantSearch.js b/packages/react-instantsearch/src/core/InstantSearch.js index 96f3cccf3a..51c66f0df4 100644 --- a/packages/react-instantsearch/src/core/InstantSearch.js +++ b/packages/react-instantsearch/src/core/InstantSearch.js @@ -68,6 +68,10 @@ class InstantSearch extends Component { if (this.props.indexName !== nextProps.indexName) { this.aisManager.updateIndex(nextProps.indexName); } + + if (this.props.algoliaClient !== nextProps.algoliaClient) { + this.aisManager.updateClient(nextProps.algoliaClient) + } if (this.isControlled) { this.aisManager.onExternalStateUpdate(nextProps.searchState); diff --git a/packages/react-instantsearch/src/core/InstantSearch.test.js b/packages/react-instantsearch/src/core/InstantSearch.test.js index 30d1c095d3..1bcb31d979 100644 --- a/packages/react-instantsearch/src/core/InstantSearch.test.js +++ b/packages/react-instantsearch/src/core/InstantSearch.test.js @@ -119,6 +119,27 @@ describe('InstantSearch', () => { }); }); + it('updates Algolia client when new one is given in props', () => { + const ism = { + updateClient: jest.fn(), + }; + + createInstantSearchManager.mockImplementation(() => ism); + + const wrapper = mount( + +
+ + ); + + expect(ism.updateClient.mock.calls.length).toBe(0); + wrapper.setProps({ + ...DEFAULT_PROPS, + algoliaClient: {}, + }); + expect(ism.updateClient.mock.calls.length).toBe(1); + }); + it('works as a controlled input', () => { const ism = { transitionState: searchState => ({ ...searchState, transitioned: true }),