Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add loader feature #818

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open

feat: Add loader feature #818

wants to merge 5 commits into from

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Dec 19, 2024

While we have the cache feature in Next.js app router to parse the incoming searchParams page prop and provide it to the rest of the RSC tree (via React's cache function, which is a hack but not the subject of this PR), other frameworks lacked the ability to parse an incoming request's search params and get the same kind of type-safe object back (without the caching part).

This PR introduces the createLoader function, a factory that takes in a search params descriptor object (a "parsers map" as we call it internally), and returns a load function. That function can then process a lot of different kinds of inputs:

  • URL object
  • Request object
  • URLSearchParams object
  • A string, whether of a fully qualified URL, or just the search part
  • A record of key/values as what Next.js usually gives us (Record<string, string | string[] | undefined>)

Compatibility

  • React Routers & Remix loaders (using a Request object)
  • Next.js pages router getServerSideProps (needs a test)
  • Next.js app router searchParams prop (async in Next 15 -> good for PPR)

Tasks

  • Add docs

Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 26, 2024 9:52pm

Copy link

pkg-pr-new bot commented Dec 19, 2024

Open in Stackblitz

npm i https://pkg.pr.new/nuqs@818

commit: 0c272cd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant