Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const stripOverwrite: QueryStateMerge = {}
// when a params are set to the same value as in the defaults
// we remove them to avoid having two URLs reproducing the same state unless stripDefaults === false
if (stripDefaults) {
Object.entries(newState).forEach(([key]) => {
if (defaultQueryState[key] === newState[key]) {
stripOverwrite[key] = null
}
})
}
// retrieve the last value (by re-executing the search getter)
const currentQueryState: QueryState = {
...defaultQueryState,
...parseQueryState(activeQSI.getQueryString()),
}
const mergedQueryString = createMergedQuery(currentQueryState || {}, newState, stripOverwrite)
activeQSI.setQueryString(mergedQueryString, opts || {})
// triggers an update (in case the QueryStringInterface misses to do so)
setLatestMergedQueryString(mergedQueryString)
}, [])
() => ({
...defaultQueryState,
...parseQueryState(queryString),
}),
[defaultQueryState, queryString]