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.15k stars 96 forks source link

V2 #222

Closed pbeshai closed 2 years ago

pbeshai commented 2 years ago

Changelog

use-query-params v2.0.0

Breaking

New Features

Fixes

Migrating from v1

There are two things you need to adjust to update from v1:

  1. Decide if you want to keep query-string as your parser/stringifier or if you want to simplify to using the built-in URLSearchParams solution in v2. The simplest path for migration is to keep your query-string dependency and specify that use-query-params should use it for searchStringToObject and objectToSearchString.
  2. Switch to using an adapter to link your routing library with use-query-params.

Here's an example of the changes to complete both for React Router 5:

import React from 'react';
import ReactDOM from 'react-dom';
import { QueryParamProvider } from 'use-query-params';
+ import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
+ import { parse, stringify } from 'query-string';
- import { BrowserRouter as Router, Route } from 'react-router-dom';
+ import { BrowserRouter as Router } from 'react-router-dom';

import App from './App';

ReactDOM.render(
  <Router>
-    <QueryParamProvider ReactRouterRoute={Route}>
+    <QueryParamProvider
+      adapter={ReactRouter5Adapter}
+      options={{
+        searchStringToObject: parse,
+        objectToSearchString: stringify,
+      }}
+    >
      <App />
    </QueryParamProvider>
  </Router>,
  document.getElementById('root')
);

If you're using react-router-6, you'd import that adapter instead:

import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';

Note the options above are optional, but will retain the behavior you're used to from v1, which used query-string internally. If you want to switch to using URLSearchParams and not use query-string, you would do:

import React from 'react';
import ReactDOM from 'react-dom';
import { QueryParamProvider } from 'use-query-params';
+ import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
- import { BrowserRouter as Router, Route } from 'react-router-dom';
+ import { BrowserRouter as Router } from 'react-router-dom';

import App from './App';

ReactDOM.render(
  <Router>
-    <QueryParamProvider ReactRouterRoute={Route}>
+    <QueryParamProvider adapter={ReactRouter5Adapter}>
      <App />
    </QueryParamProvider>
  </Router>,
  document.getElementById('root')
);

Changelog

serialize-query-params v2.0.0

Breaking

New Features

marhaupe commented 2 years ago

So far rc.0 looks good! Are there any other tasks to be done before it is considered stable or are you just going to wait a few weeks to make sure it doesn't break stuff for most users?

pbeshai commented 2 years ago

I'm not expecting any changes, just want to give it a week or two then I'll release v2 proper

marhaupe commented 2 years ago

Awesome! Also thanks for the work, v2 looks like a milestone!

ingvaldlorentzen commented 2 years ago

The changelog and migration guide here is great. Maybe add it as a release under the GitHub releases so it's easier for people to find?