Skip to content

Commit

Permalink
refactor: Name is explicit that the hook is not generic but is only a…
Browse files Browse the repository at this point in the history
…bout browse params
  • Loading branch information
ptbrowne committed May 28, 2024
1 parent fbb95ac commit 2c04249
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/browser/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const urlCodec: BrowseParamsCodec = {
serialize: buildURLFromBrowseState,
};

const useQueryParamsState = (initialState: BrowseParams) => {
const useBrowseParamsStateWithUrlSync = (initialState: BrowseParams) => {
const router = useRouter();

const [state, rawSetState] = useState(() => {
Expand Down Expand Up @@ -140,9 +140,14 @@ const useQueryParamsState = (initialState: BrowseParams) => {
return [state, setState] as const;
};

/**
* Creates a hook that provides the current browse state and actions to update it.
*
* It will persist/recover this state from the URL if `syncWithUrl` is true.
*/
const createUseBrowseState = ({ syncWithUrl }: { syncWithUrl: boolean }) => {
const useParamsHook = syncWithUrl
? useQueryParamsState
? useBrowseParamsStateWithUrlSync
: useState<BrowseParams>;
return () => {
const inputRef = useRef<HTMLInputElement>(null);
Expand Down

0 comments on commit 2c04249

Please sign in to comment.