-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Add inertia community adapter docs #787
base: next
Are you sure you want to change the base?
Conversation
@Joehoel is attempting to deploy a commit to the 47ng Team on Vercel. A member of the Team first needs to authorize it. |
Also might be related: inertiajs/inertia#2110 While creating the adapter I was facing some issues with persistent layouts from inertia and the state not updating correctly. Anyone face similar issues? |
Echoing my inertiajs/inertia#2110 (comment), the key thing for adapters to work is that the This is unfortunately not an easy thing to do, and it looks like most adapters (apart from Next.js which does some of that for us) need to do the same kind of heavy lifting work to get this reactive value. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks for clarifying. I can look into it when I have some extra time but if someone else wants to have a stab! Maybe we can take some inspiration from the remix/react-router code for the reactive search params? |
I have some updates for the Remix adapter that I need to test & push, it's adding a lot of those things I mentioned but it could probably be refactored to benefit a lot of other adapters. I might have more time to work on that next week. |
Just realised Inertia has a usePage hook. import { router, usePage } from "@inertiajs/react";
import {
type unstable_AdapterOptions as AdapterOptions,
unstable_createAdapterProvider as createAdapterProvider,
renderQueryString,
} from "nuqs/adapters/custom";
function useNuqsInertiaAdapter() {
const { searchParams } = new URL(location.origin + usePage().url);
function updateUrl(search: URLSearchParams, options: AdapterOptions) {
const url = new URL(location.href);
url.search = renderQueryString(search);
router.visit(url, {
replace: options.history === "replace",
preserveScroll: !options.scroll,
preserveState: options.shallow,
});
}
return {
searchParams,
updateUrl,
};
}
export const NuqsAdapter = createAdapterProvider(useNuqsInertiaAdapter); Implemented this is my test app and it works and fixes this issue inertiajs/inertia#2110 (comment) |
Looks good! However I think the shallow option doesn't really map to Inertia's state preservation mechanism. In nuqs, The history API part is also something that could be factored out of all of those adapters. |
This PR adds documentation for a community adapter for Inertia.js. Inspired by the conversations on X. Related #786