react-instantsearch-core
Version:
⚡ Lightning-fast search for React, by Algolia
31 lines • 1.5 kB
JavaScript
var _excluded = ["children"];
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import React, { useEffect } from 'react';
import { IndexContext } from "../lib/IndexContext.js";
import { InstantSearchContext } from "../lib/InstantSearchContext.js";
import { useInstantSearchApi } from "../lib/useInstantSearchApi.js";
export function InstantSearch(_ref) {
var children = _ref.children,
props = _objectWithoutProperties(_ref, _excluded);
var search = useInstantSearchApi(props);
if (!search.started) {
return null;
}
return /*#__PURE__*/React.createElement(InstantSearchContext.Provider, {
value: search
}, /*#__PURE__*/React.createElement(IndexContext.Provider, {
value: search.mainIndex
}, children, /*#__PURE__*/React.createElement(ResetScheduleSearch, {
search: search
})));
}
function ResetScheduleSearch(_ref2) {
var search = _ref2.search;
useEffect(function () {
if (search._resetScheduleSearch) {
search._resetScheduleSearch();
}
}, [search]);
return null;
}