From 41584bc8d83817f2f2836bf2761755e7715bf186 Mon Sep 17 00:00:00 2001 From: taisei mima Date: Sat, 22 Jan 2022 01:19:21 +0900 Subject: [PATCH] docs: Fix types related to history State (#8601) --- contributors.yml | 1 + docs/api.md | 51 ++++++++++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/contributors.yml b/contributors.yml index 540376407..93884ebc7 100644 --- a/contributors.yml +++ b/contributors.yml @@ -28,3 +28,4 @@ - turansky - underager - vijaypushkin +- bhbs diff --git a/docs/api.md b/docs/api.md index bb8776716..163a2cd65 100644 --- a/docs/api.md +++ b/docs/api.md @@ -310,7 +310,7 @@ interface LinkProps extends TouchableHighlightProps { children?: React.ReactNode; onPress?(event: GestureResponderEvent): void; replace?: boolean; - state?: State; + state?: any; to: To; } ``` @@ -475,7 +475,7 @@ declare function Navigate(props: NavigateProps): null; interface NavigateProps { to: To; replace?: boolean; - state?: State; + state?: any; } ``` @@ -831,7 +831,7 @@ The term "location" in React Router refers to [the `Location` interface](https:/ > > The `history` package is React Router's only dependency and many of the > core types in React Router come directly from that library including -> `Location`, `To`, `Path`, `State`, and others. You can read more about +> `Location`, `To`, `Path`, and others. You can read more about > the history library in [its documentation](https://github.com/remix-run/history/tree/main/docs). ### `matchRoutes` @@ -957,15 +957,12 @@ The `useHref` hook returns a URL that may be used to link to the given `to` loca Type declaration ```tsx -declare function useLinkClickHandler< - E extends Element = HTMLAnchorElement, - S extends State = State ->( +declare function useLinkClickHandler( to: To, options?: { target?: React.HTMLAttributeAnchorTarget; replace?: boolean; - state?: S; + state?: any; } ): (event: React.MouseEvent) => void; ``` @@ -1025,13 +1022,11 @@ const Link = React.forwardRef( Type declaration ```tsx -declare function useLinkPressHandler< - S extends State = State ->( +declare function useLinkPressHandler( to: To, options?: { replace?: boolean; - state?: S; + state?: any; } ): (event: GestureResponderEvent) => void; ``` @@ -1091,9 +1086,8 @@ The `useInRouterContext` hooks returns `true` if the component is being rendered ```tsx declare function useLocation(): Location; -interface Location - extends Path { - state: S; +interface Location extends Path { + state: unknown; key: Key; } ``` @@ -1315,7 +1309,7 @@ function App() { ```tsx declare function useSearchParams( defaultInit?: URLSearchParamsInit -): [URLSearchParams, URLSearchParamsSetter]; +): [URLSearchParams, SetURLSearchParams]; type ParamKeyValuePair = [string, string]; @@ -1325,12 +1319,10 @@ type URLSearchParamsInit = | Record | URLSearchParams; -interface URLSearchParamsSetter { - ( - nextInit: URLSearchParamsInit, - navigateOptions?: { replace?: boolean; state?: State } - ): void; -} +type SetURLSearchParams = ( + nextInit?: URLSearchParamsInit, + navigateOpts?: : { replace?: boolean; state?: any } +) => void; ``` @@ -1381,7 +1373,7 @@ function App() { ```tsx declare function useSearchParams( defaultInit?: URLSearchParamsInit -): [URLSearchParams, URLSearchParamsSetter]; +): [URLSearchParams, SetURLSearchParams]; type ParamKeyValuePair = [string, string]; @@ -1391,11 +1383,14 @@ type URLSearchParamsInit = | Record | URLSearchParams; -interface URLSearchParamsSetter { - ( - nextInit: URLSearchParamsInit, - navigateOptions?: { replace?: boolean; state?: State } - ): void; +type SetURLSearchParams = ( + nextInit?: URLSearchParamsInit, + navigateOpts?: : NavigateOptions +) => void; + +interface NavigateOptions { + replace?: boolean; + state?: any; } ```