@finos/legend-application
Version:
Legend application core
35 lines • 2.11 kB
TypeScript
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { SetURLSearchParams } from 'react-router';
/**
* Util hook to keep a state variable in sync with a URL search parameter.
* This hook syncs from URL to state if the state is null/undefined (so
* initial value is set from URL) and from state to URL otherwise.
*
* This hook properly queues setSearchParams calls to ensure all updates
* are applied, working around react-router's limitation where multiple
* calls to setSearchParams in the same tick don't build on each other.
* See: https://github.com/remix-run/react-router/issues/9304
*
* @param stateVar the state variable to sync
* @param updateStateVar setter function to update the state variable (should be memoized with useCallback)
* @param searchParamKey the key of the URL search parameter to sync with
* @param searchParamValue the current URL search parameter value (i.e., from useSearchParams)
* @param setSearchParams function to update the URL search parameters (i.e., from useSearchParams)
* @param initializedCallback function to check if the underlying state is initialized and ready to sync with URL (should be memoized with useCallback)
*/
export declare const useSyncStateAndSearchParam: (stateVar: string | boolean | number | null | undefined, updateStateVar: (val: string | null) => void, searchParamKey: string, searchParamValue: string | null, setSearchParams: SetURLSearchParams, initializedCallback: () => boolean, clearParamOnUnmount?: boolean) => void;
//# sourceMappingURL=URLUtils.d.ts.map