Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
next-query-params
Advanced tools
Convenient state management of query parameters in Next.js apps.
[!WARNING]
This project is in maintainence mode now. I've originally created it for the Pages Router, but with the introduction of the App Router there are now better patterns for handling query params in my opinion. Personally, I parsesearchParams
in pages withzod
. If you need something more advanced, you might want to have a look at nuqs.
Convenient state management of query parameters in Next.js apps.
Persisting React state to query parameters is often a good idea:
This library is an adapter for use-query-params
to integrate with Next.js.
npm install next-query-params use-query-params
// app/layout.tsx
'use client';
import NextAdapterApp from 'next-query-params/app';
import {QueryParamProvider} from 'use-query-params';
export default function RootLayout({children}) {
return (
<html lang="en">
<body>
<QueryParamProvider adapter={NextAdapterApp}>
{children}
</QueryParamProvider>
</body>
</html>
);
}
// _app.tsx
import NextAdapterPages from 'next-query-params/pages';
import {QueryParamProvider} from 'use-query-params';
export default function App({Component, pageProps}) {
return (
<QueryParamProvider adapter={NextAdapterPages}>
<Component {...pageProps} />
</QueryParamProvider>
);
}
Please refer to the usage of use-query-params
.
import {useQueryParam, StringParam, withDefault} from 'use-query-params';
export default function IndexPage() {
const [name, setName] = useQueryParam('name', withDefault(StringParam, ''));
function onNameInputChange(event) {
setName(event.target.value);
}
return (
<p>My name is <input value={name} onChange={onNameInputChange} /></p>
);
}
NextAdapter
can be configured to opt-out of shallow routing. In this case server-side functions like getServerSideProps
will be run again when a query parameter changes.
// _app.tsx
import NextAdapterPages from 'next-query-params/pages';
import {QueryParamProvider} from 'use-query-params';
function Adapter(props) {
return <NextAdapter {...props} shallow={false} />;
}
export default function App({Component, pageProps}) {
return (
<QueryParamProvider adapter={Adapter}>
<Component {...pageProps} />
</QueryParamProvider>
);
}
This library is an adapter for use-query-params
by Peter Beshai and was originally based on the code that was collaboratively created in use-query-params#13.
FAQs
Convenient state management of query parameters in Next.js apps.
The npm package next-query-params receives a total of 29,017 weekly downloads. As such, next-query-params popularity was classified as popular.
We found that next-query-params demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.