react-instantsearch-nextjs
Version:
React InstantSearch SSR utilities for Next.js
19 lines • 876 B
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import { headers } from "next/headers.js";
import { use } from 'react';
function isPromise(obj) {
return obj && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
}
export var useNextHeaders = function useNextHeaders() {
var isServer = typeof window === 'undefined';
var h;
if (isServer) {
var nextHeaders = headers();
if (isPromise(headers())) {
h = use(nextHeaders);
} else {
h = nextHeaders; // assert that headers come from the synchronous nextjs function
}
}
return h;
};