react-instantsearch-nextjs
Version:
React InstantSearch SSR utilities for Next.js
30 lines (28 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useDynamicRouteWarning", {
enumerable: true,
get: function() {
return useDynamicRouteWarning;
}
});
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _navigation = require("next/navigation");
var _warn = require("./warn");
var lastParams = null;
function useDynamicRouteWarning(param) {
var isServer = param.isServer, isMounting = param.isMounting, instance = param.instance;
var params = (0, _navigation.useParams)();
if (!isServer && isMounting.current && !instance) {
// Warn if lastParams and current params have the same keys but different values
if (lastParams && Object.keys(lastParams).length === Object.keys(params).length && Object.entries(lastParams).some(function(param) {
var _param = _sliced_to_array._(param, 2), key = _param[0], value = _param[1];
return params[key] !== value;
})) {
(0, _warn.warn)(false, "\nWe detected you may be using `<InstantSearchNext>` on a dynamic route.\n\nThis can lead to unexpected behavior, we recommend passing an `instance` prop to <InstantSearchNext>, created from the `createInstantSearchNextInstance` function.\n\nThis message can be safely ignored if you are not using dynamic routes.\n\nFor more information, see https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#dynamic-routes\n");
}
lastParams = params;
}
}