Skip to Content
BBRICKSv0.7.4
DataHooks

useUrlParams

The shared body of useHashState / useQueryState, with the location as a value.

import { useUrlParams } from '@ergasti/bricks';

Examples

Choose the place

useUrlParams(location, namespace, defaults) is what useHashState and useQueryState call; pass 'hash' or 'query' yourself when the place is decided at run time.

Code
import { useUrlParams } from '@ergasti/bricks';

function Place() {
  const [state, setState] = useUrlParams('query', 'docs-place', { tab: 'one' });
  return <div style={{ display: 'flex', gap: 8, alignItems: 'center' }}><button type="button" className="kit-btn" onClick={() => setState({ tab: state.tab === 'one' ? 'two' : 'one' })}>Flip</button><small>{JSON.stringify(state)}</small></div>;
}

Signature

function useUrlParams<S>(location: UrlLocation, namespace: string, defaults: S, options?: WriteOptions): [S, UrlStateSetter<S>, () => void]

Parameters

Prop

Type

Returns

[S, UrlStateSetter<S>, () => void]

useAction · useDataLanguage · useDebouncedCallback · useDrawerResource

Source

src/data/useUrlState.ts (line 12) on GitHub.

On this page