Closed pbeshai closed 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?
I'm not expecting any changes, just want to give it a week or two then I'll release v2 proper
Awesome! Also thanks for the work, v2 looks like a milestone!
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?
Changelog
use-query-params v2.0.0
Breaking
null
. You can continue using query-string by specifying thesearchStringToObject
andobjectToSearchString
options as parse and stringify respectively.New Features
Deep imports for React-Router 5 and 6 adapters
Supports registering params in the QueryParamProvider to have them available to any downstream hooks.
Additional function signatures have been added, but greater care must be taken to get proper types out of the response.
useQueryParam(’myparam’)
← param type is inherited from the params registered in the QueryParamProvideruseQueryParam(’myparam’, StringParam, options)
useQueryParams()
← gets all params from the QueryParamProvideruseQueryParams([’myparam1’, ‘myparam2’])
← gets just myparam1 and myparam2 from those registered in the QueryParamProvider.useQueryParams({ myparam: StringParam }, options)
useQueryParams({ myparam: ‘inherit’ }, options)
←inherit myparam param name from QueryParamProviderNew
options
prop to QueryParamProvider and argument to useQueryParam(s)enableBatching
option (i.e., multiple consecutive calls to setQueryParams in a row only result in a single update to the URL). This seems to work but would require updating the way all the tests are written to verify for sure, so marking as experimental for now.removeDefaultsFromUrl
(default: false). This happens on updates only, not on initial load. Requires the use of thedefault
attribute on a parameter to function (note serialize-query-params v2 withDefault now populates this).includeKnownParams
- in addition to those specified, also include all preconfigured parameters from the QueryParamProviderincludeAllParams
(default: false) - in addition to those specified, include all other parameters found in the current URLupdateType
(default “pushIn”) - the default update type when set is called.searchStringToObject, objectToSearchString
(default uses URLSearchParams) - equivalent ofparse
andstringify
from query-string.Parameters now can include
urlName
to automatically convert to a different name in the URL (e.g. { encode, decode, urlName })Caches decoded values across multiple hook calls from different components
Fixes
Migrating from v1
There are two things you need to adjust to update from v1:
searchStringToObject
andobjectToSearchString
.Here's an example of the changes to complete both for React Router 5:
If you're using react-router-6, you'd import that adapter instead:
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:Changelog
serialize-query-params v2.0.0
Breaking
updateLocation
andupdateInLocation
.New Features
objectToSearchString
- small wrapper around URLSearchParams that handles undefined, null, and array values. A lesser version of query-string’s “stringify”searchStringToObject
- small wrapper around URLSearchParams that handles array values. A lesser version of query-string’s “parse”createEnumArrayParam
andcreateEnumDelimitedArrayParam
helpersdefault
andurlName
as optional attributes of a Parameter, mostly for other tooling to introspect on. Note thatwithDefault
now populates thedefault
attribute.