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

fix: be more defensive about reading updateType #223

Closed pbeshai closed 2 years ago

pbeshai commented 2 years ago

Sometimes you may want to pass the setter from useQueryParams to some kind of event handler which supplies more args than necessary. e.g. onClick={(value, otherStuff) => setQueryParam(value)} but you instead do onClick={setQueryParam}. The setter will interpret that second argument as the updateType which could cause problems. Really, this is a problem in the user code, but in v1 this wasn't a problem, so I'm putting in a defensive check to ensure updateType is a string before calling startsWith on it.