Skip to content

Conversation

@baptisteArno
Copy link
Contributor

Improve useQueryParams hook typing by specifying a type as an argument.

Example:

type MyRouteQueryParams = {
      sort?: string
      filter?: string[]
}

const { setQueryParams, replaceQueryParams} = useQueryParams<MyRouteQueryParams>()

setQueryParams( { anotherParam: "test" } )
                 // 👆 Argument of type '{ anotherParam: string; }' is not assignable to parameter of type 'Partial<RouteQueryParams>'

replaceQueryParams({ test: 'test' })
                    // 👆 Argument of type '{ test: string; }' is not assignable to parameter of type 'RouteQueryParams'.

@baptisteArno baptisteArno added the enhancement New feature or request label Sep 15, 2022
@baptisteArno baptisteArno self-assigned this Sep 15, 2022
@baptisteArno baptisteArno force-pushed the feat/add-generic-type-to-use-query-params branch from 81493f8 to f8fd97f Compare September 15, 2022 12:49
@codecov
Copy link

codecov bot commented Sep 15, 2022

Codecov Report

Merging #985 (f8fd97f) into main (c7effff) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #985   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines          568       568           
  Branches        78        78           
=========================================
  Hits           568       568           
Impacted Files Coverage Δ
packages/use-query-params/src/index.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@baptisteArno baptisteArno changed the title feat(usequeryparams): add generic typing feat(useQueryParams): add generic typing Sep 15, 2022
@baptisteArno baptisteArno merged commit 8a47239 into main Sep 15, 2022
@baptisteArno baptisteArno deleted the feat/add-generic-type-to-use-query-params branch September 15, 2022 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants