@fobos531/nuqs
Version:
Type-safe search params state manager for Next.js - Like React.useState, but stored in the URL query string
46 lines (42 loc) • 1.08 kB
JavaScript
'use client';
import { resetQueue } from '../chunk-AOGHIZZC.js';
import '../chunk-3RCMAOX7.js';
import { context, renderQueryString } from '../chunk-SDEJ2M24.js';
import { createElement } from 'react';
function NuqsTestingAdapter({
resetUrlUpdateQueueOnMount = true,
...props
}) {
if (resetUrlUpdateQueueOnMount) {
resetQueue();
}
const useAdapter = () => ({
searchParams: new URLSearchParams(props.searchParams),
updateUrl(search, options) {
props.onUrlUpdate?.({
searchParams: search,
queryString: renderQueryString(search),
options
});
},
rateLimitFactor: props.rateLimitFactor ?? 0
});
return createElement(
context.Provider,
{ value: { useAdapter } },
props.children
);
}
function withNuqsTestingAdapter(props = {}) {
return function NuqsTestingAdapterWrapper({
children
}) {
return createElement(
NuqsTestingAdapter,
// @ts-expect-error - Ignore missing children error
props,
children
);
};
}
export { NuqsTestingAdapter, withNuqsTestingAdapter };