pbeshai / use-query-params

React Hook for managing state in URL query parameters with easy serialization.
https://pbeshai.github.io/use-query-params
ISC License
2.13k stars 95 forks source link

Not compatible with react router v6.4 #243

Closed iamyoki closed 1 year ago

iamyoki commented 1 year ago

React router v6.4 introduced a new way of creating router (https://reactrouter.com/en/main/routers/create-browser-router), so that leads to no longer possible to place <QueryParamProvider />under <RouterProvider />

image

pbeshai commented 1 year ago

Based on the linked docs, it seems like you should be able to just wrap the Root component with QueryParamProvider – is this not the case? e.g.

const router = createBrowserRouter([
  {
    path: "/",
    element: <QueryParamProvider><Root /></QueryParamProvider>,
    loader: rootLoader,
    children: [
      {
        path: "team",
        element: <Team />,
        loader: teamLoader,
      },
    ],
  },
]);

ReactDOM.createRoot(document.getElementById("root")).render(
  <RouterProvider router={router} />
);
marhaupe commented 1 year ago

Can confirm that this should work. We basically did the same thing @pbeshai suggested. Bear in mind that you might need to add an <Outlet/> to whatever the equivalent to <Root/> is in your project.