MCPcopy Index your code
hub / github.com/adobe/react-spectrum / RouterProvider

Function RouterProvider

packages/react-aria/src/utils/openLink.tsx:53–79  ·  view source on GitHub ↗
(props: RouterProviderProps)

Source from the content-addressed store, hash-verified

51 * and provides it to all nested React Aria links to enable client side navigation.
52 */
53export function RouterProvider(props: RouterProviderProps): JSX.Element {
54 let {children, navigate, useHref} = props;
55
56 let ctx = useMemo(
57 () => ({
58 isNative: false,
59 open: (
60 target: Element,
61 modifiers: Modifiers,
62 href: Href,
63 routerOptions: RouterOptions | undefined
64 ) => {
65 getSyntheticLink(target, link => {
66 if (shouldClientNavigate(link, modifiers)) {
67 navigate(href, routerOptions);
68 } else {
69 openLink(link, modifiers);
70 }
71 });
72 },
73 useHref: useHref || (href => href)
74 }),
75 [navigate, useHref]
76 );
77
78 return <RouterContext.Provider value={ctx}>{children}</RouterContext.Provider>;
79}
80
81export function useRouter(): Router {
82 return useContext(RouterContext);

Callers

nothing calls this directly

Calls 4

getSyntheticLinkFunction · 0.85
shouldClientNavigateFunction · 0.85
openLinkFunction · 0.85
navigateFunction · 0.50

Tested by

no test coverage detected