source: node_modules/react-router-dom/dist/index.d.ts@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 13.8 KB
Line 
1/**
2 * NOTE: If you refactor this to split up the modules into separate files,
3 * you'll need to update the rollup config for react-router-dom-v5-compat.
4 */
5import * as React from "react";
6import type { FutureConfig, Location, NavigateOptions, RelativeRoutingType, RouteObject, RouterProviderProps, To } from "react-router";
7import type { Fetcher, FormEncType, FormMethod, FutureConfig as RouterFutureConfig, GetScrollRestorationKeyFunction, History, HTMLFormMethod, HydrationState, Router as RemixRouter, V7_FormMethod, BlockerFunction } from "@remix-run/router";
8import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit, SubmitTarget } from "./dom";
9import { createSearchParams } from "./dom";
10export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, V7_FormMethod, };
11export { createSearchParams };
12export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker, BlockerFunction, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathParam, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, To, UIMatch, } from "react-router";
13export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
14/** @internal */
15export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, } from "react-router";
16declare global {
17 var __staticRouterHydrationData: HydrationState | undefined;
18 var __reactRouterVersion: string;
19 interface Document {
20 startViewTransition(cb: () => Promise<void> | void): ViewTransition;
21 }
22}
23interface DOMRouterOpts {
24 basename?: string;
25 future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
26 hydrationData?: HydrationState;
27 window?: Window;
28}
29export declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter;
30export declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter;
31type ViewTransitionContextObject = {
32 isTransitioning: false;
33} | {
34 isTransitioning: true;
35 flushSync: boolean;
36 currentLocation: Location;
37 nextLocation: Location;
38};
39declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
40export { ViewTransitionContext as UNSAFE_ViewTransitionContext };
41type FetchersContextObject = Map<string, any>;
42declare const FetchersContext: React.Context<FetchersContextObject>;
43export { FetchersContext as UNSAFE_FetchersContext };
44interface ViewTransition {
45 finished: Promise<void>;
46 ready: Promise<void>;
47 updateCallbackDone: Promise<void>;
48 skipTransition(): void;
49}
50/**
51 * Given a Remix Router instance, render the appropriate UI
52 */
53export declare function RouterProvider({ fallbackElement, router, future, }: RouterProviderProps): React.ReactElement;
54export interface BrowserRouterProps {
55 basename?: string;
56 children?: React.ReactNode;
57 future?: Partial<FutureConfig>;
58 window?: Window;
59}
60/**
61 * A `<Router>` for use in web browsers. Provides the cleanest URLs.
62 */
63export declare function BrowserRouter({ basename, children, future, window, }: BrowserRouterProps): React.JSX.Element;
64export interface HashRouterProps {
65 basename?: string;
66 children?: React.ReactNode;
67 future?: Partial<FutureConfig>;
68 window?: Window;
69}
70/**
71 * A `<Router>` for use in web browsers. Stores the location in the hash
72 * portion of the URL so it is not sent to the server.
73 */
74export declare function HashRouter({ basename, children, future, window, }: HashRouterProps): React.JSX.Element;
75export interface HistoryRouterProps {
76 basename?: string;
77 children?: React.ReactNode;
78 future?: FutureConfig;
79 history: History;
80}
81/**
82 * A `<Router>` that accepts a pre-instantiated history object. It's important
83 * to note that using your own history object is highly discouraged and may add
84 * two versions of the history library to your bundles unless you use the same
85 * version of the history library that React Router uses internally.
86 */
87declare function HistoryRouter({ basename, children, future, history, }: HistoryRouterProps): React.JSX.Element;
88declare namespace HistoryRouter {
89 var displayName: string;
90}
91export { HistoryRouter as unstable_HistoryRouter };
92export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
93 reloadDocument?: boolean;
94 replace?: boolean;
95 state?: any;
96 preventScrollReset?: boolean;
97 relative?: RelativeRoutingType;
98 to: To;
99 unstable_viewTransition?: boolean;
100}
101/**
102 * The public API for rendering a history-aware `<a>`.
103 */
104export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
105type NavLinkRenderProps = {
106 isActive: boolean;
107 isPending: boolean;
108 isTransitioning: boolean;
109};
110export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
111 children?: React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode);
112 caseSensitive?: boolean;
113 className?: string | ((props: NavLinkRenderProps) => string | undefined);
114 end?: boolean;
115 style?: React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties | undefined);
116}
117/**
118 * A `<Link>` wrapper that knows if it's "active" or not.
119 */
120export declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
121export interface FetcherFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
122 /**
123 * The HTTP verb to use when the form is submit. Supports "get", "post",
124 * "put", "delete", "patch".
125 */
126 method?: HTMLFormMethod;
127 /**
128 * `<form encType>` - enhancing beyond the normal string type and limiting
129 * to the built-in browser supported values
130 */
131 encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
132 /**
133 * Normal `<form action>` but supports React Router's relative paths.
134 */
135 action?: string;
136 /**
137 * Determines whether the form action is relative to the route hierarchy or
138 * the pathname. Use this if you want to opt out of navigating the route
139 * hierarchy and want to instead route based on /-delimited URL segments
140 */
141 relative?: RelativeRoutingType;
142 /**
143 * Prevent the scroll position from resetting to the top of the viewport on
144 * completion of the navigation when using the <ScrollRestoration> component
145 */
146 preventScrollReset?: boolean;
147 /**
148 * A function to call when the form is submitted. If you call
149 * `event.preventDefault()` then this form will not do anything.
150 */
151 onSubmit?: React.FormEventHandler<HTMLFormElement>;
152}
153export interface FormProps extends FetcherFormProps {
154 /**
155 * Indicate a specific fetcherKey to use when using navigate=false
156 */
157 fetcherKey?: string;
158 /**
159 * navigate=false will use a fetcher instead of a navigation
160 */
161 navigate?: boolean;
162 /**
163 * Forces a full document navigation instead of a fetch.
164 */
165 reloadDocument?: boolean;
166 /**
167 * Replaces the current entry in the browser history stack when the form
168 * navigates. Use this if you don't want the user to be able to click "back"
169 * to the page with the form on it.
170 */
171 replace?: boolean;
172 /**
173 * State object to add to the history stack entry for this navigation
174 */
175 state?: any;
176 /**
177 * Enable view transitions on this Form navigation
178 */
179 unstable_viewTransition?: boolean;
180}
181/**
182 * A `@remix-run/router`-aware `<form>`. It behaves like a normal form except
183 * that the interaction with the server is with `fetch` instead of new document
184 * requests, allowing components to add nicer UX to the page as the form is
185 * submitted and returns with data.
186 */
187export declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
188export interface ScrollRestorationProps {
189 getKey?: GetScrollRestorationKeyFunction;
190 storageKey?: string;
191}
192/**
193 * This component will emulate the browser's scroll restoration on location
194 * changes.
195 */
196export declare function ScrollRestoration({ getKey, storageKey, }: ScrollRestorationProps): null;
197export declare namespace ScrollRestoration {
198 var displayName: string;
199}
200/**
201 * Handles the click behavior for router `<Link>` components. This is useful if
202 * you need to create custom `<Link>` components with the same click behavior we
203 * use in our exported `<Link>`.
204 */
205export declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, unstable_viewTransition, }?: {
206 target?: React.HTMLAttributeAnchorTarget;
207 replace?: boolean;
208 state?: any;
209 preventScrollReset?: boolean;
210 relative?: RelativeRoutingType;
211 unstable_viewTransition?: boolean;
212}): (event: React.MouseEvent<E, MouseEvent>) => void;
213/**
214 * A convenient wrapper for reading and writing search parameters via the
215 * URLSearchParams interface.
216 */
217export declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
218export type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
219/**
220 * Submits a HTML `<form>` to the server without reloading the page.
221 */
222export interface SubmitFunction {
223 (
224 /**
225 * Specifies the `<form>` to be submitted to the server, a specific
226 * `<button>` or `<input type="submit">` to use to submit the form, or some
227 * arbitrary data to submit.
228 *
229 * Note: When using a `<button>` its `name` and `value` will also be
230 * included in the form data that is submitted.
231 */
232 target: SubmitTarget,
233 /**
234 * Options that override the `<form>`'s own attributes. Required when
235 * submitting arbitrary data without a backing `<form>`.
236 */
237 options?: SubmitOptions): void;
238}
239/**
240 * Submits a fetcher `<form>` to the server without reloading the page.
241 */
242export interface FetcherSubmitFunction {
243 (target: SubmitTarget, options?: Omit<SubmitOptions, "replace" | "state">): void;
244}
245/**
246 * Returns a function that may be used to programmatically submit a form (or
247 * some arbitrary data) to the server.
248 */
249export declare function useSubmit(): SubmitFunction;
250export declare function useFormAction(action?: string, { relative }?: {
251 relative?: RelativeRoutingType;
252}): string;
253export type FetcherWithComponents<TData> = Fetcher<TData> & {
254 Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
255 submit: FetcherSubmitFunction;
256 load: (href: string, opts?: {
257 unstable_flushSync?: boolean;
258 }) => void;
259};
260/**
261 * Interacts with route loaders and actions without causing a navigation. Great
262 * for any interaction that stays on the same page.
263 */
264export declare function useFetcher<TData = any>({ key, }?: {
265 key?: string;
266}): FetcherWithComponents<TData>;
267/**
268 * Provides all fetchers currently on the page. Useful for layouts and parent
269 * routes that need to provide pending/optimistic UI regarding the fetch.
270 */
271export declare function useFetchers(): (Fetcher & {
272 key: string;
273})[];
274/**
275 * When rendered inside a RouterProvider, will restore scroll positions on navigations
276 */
277declare function useScrollRestoration({ getKey, storageKey, }?: {
278 getKey?: GetScrollRestorationKeyFunction;
279 storageKey?: string;
280}): void;
281export { useScrollRestoration as UNSAFE_useScrollRestoration };
282/**
283 * Setup a callback to be fired on the window's `beforeunload` event. This is
284 * useful for saving some data to `window.localStorage` just before the page
285 * refreshes.
286 *
287 * Note: The `callback` argument should be a function created with
288 * `React.useCallback()`.
289 */
290export declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
291 capture?: boolean;
292}): void;
293/**
294 * Wrapper around useBlocker to show a window.confirm prompt to users instead
295 * of building a custom UI with useBlocker.
296 *
297 * Warning: This has *a lot of rough edges* and behaves very differently (and
298 * very incorrectly in some cases) across browsers if user click addition
299 * back/forward navigations while the confirm is open. Use at your own risk.
300 */
301declare function usePrompt({ when, message, }: {
302 when: boolean | BlockerFunction;
303 message: string;
304}): void;
305export { usePrompt as unstable_usePrompt };
306/**
307 * Return a boolean indicating if there is an active view transition to the
308 * given href. You can use this value to render CSS classes or viewTransitionName
309 * styles onto your elements
310 *
311 * @param href The destination href
312 * @param [opts.relative] Relative routing type ("route" | "path")
313 */
314declare function useViewTransitionState(to: To, opts?: {
315 relative?: RelativeRoutingType;
316}): boolean;
317export { useViewTransitionState as unstable_useViewTransitionState };
Note: See TracBrowser for help on using the repository browser.