import { useCallback } from 'react' ; import { useShallowEqual } from '@tinkoff/react-hooks' ; import { useRouter } from './useRouter' ; import type { NavigateOptions } from '../../types' ; interface UseNavigate { ( rootOptions ) : ( ) => Promise < void > ; ( ) : ( specificOptions : NavigateOptions | string ) => Promise < void > ; } const convertToNavigateOptions = ( options ) => { return typeof options === 'string' ? { url : options } : options ; } ; export const useNavigate = ( rootOptions ? ) => { const router = useRouter ( ) ; const rootOpts = useShallowEqual ( convertToNavigateOptions ( rootOptions ) ) ; return useCallback ( ( specificOptions ? ) => { const opts = rootOpts ?? convertToNavigateOptions ( specificOptions ) ; return router . navigate ( opts ) ; } , [ rootOpts , router ] ) ; } ;