How to use the query-state-core.parseQueryState function in query-state-core

To help you get started, we’ve selected a few query-state-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xiel / use-location-state / src / packages / use-location-state / src / useQueryState / useQueryStateObj.ts View on Github external
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)
  }, [])
github xiel / use-location-state / src / packages / use-location-state / src / useQueryState / useQueryStateObj.ts View on Github external
() => ({
      ...defaultQueryState,
      ...parseQueryState(queryString),
    }),
    [defaultQueryState, queryString]

query-state-core

thin layer on around URLSearchParams to parse/merge/stringify QueryStates

MIT
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages