@@ -53,59 +53,38 @@ Here are some examples of how you can use `createLink` with third-party librarie
53
53
54
54
### React Aria Components example
55
55
56
- React Aria Components'
57
- [ Link] ( https://react-spectrum.adobe.com/react-aria/Link.html ) component does not support the standard ` onMouseEnter ` and ` onMouseLeave ` events.
58
- Therefore, you cannot use it directly with TanStack Router's ` preload (intent) ` prop.
59
-
60
- Explanation for this can be found here:
61
-
62
- - [ https://react-spectrum.adobe.com/react-aria/interactions.html ] ( https://react-spectrum.adobe.com/react-aria/interactions.html )
63
- - [ https://react-spectrum.adobe.com/blog/building-a-button-part-2.html ] ( https://react-spectrum.adobe.com/blog/building-a-button-part-2.html )
64
-
65
- It is possible to work around this by using the [ useLink] ( https://react-spectrum.adobe.com/react-aria/useLink.html ) hook from [ React Aria Hooks] ( https://react-spectrum.adobe.com/react-aria/hooks.html ) with a standard anchor element.
56
+ React Aria Components v1.11.0 and later works with TanStack Router's ` preload (intent) ` prop. Use ` createLink ` to wrap each React Aria component that you use as a link.
66
57
67
58
``` tsx
68
- import * as React from ' react'
69
- import { createLink , LinkComponent } from ' @tanstack/react-router'
70
- import {
71
- mergeProps ,
72
- useFocusRing ,
73
- useHover ,
74
- useLink ,
75
- useObjectRef ,
76
- } from ' react-aria'
77
- import type { AriaLinkOptions } from ' react-aria'
78
-
79
- interface RACLinkProps extends Omit <AriaLinkOptions , ' href' > {
80
- children? : React .ReactNode
81
- }
59
+ import { createLink } from ' @tanstack/react-router'
60
+ import { Link as RACLink , MenuItem } from ' react-aria-components'
82
61
83
- const RACLinkComponent = React . forwardRef < HTMLAnchorElement , RACLinkProps >(
84
- ( props , forwardedRef ) => {
85
- const ref = useObjectRef ( forwardedRef )
62
+ export const Link = createLink ( RACLink )
63
+ export const MenuItemLink = createLink ( MenuItem )
64
+ ```
86
65
87
- const { isPressed, linkProps } = useLink (props , ref )
88
- const { isHovered, hoverProps } = useHover (props )
89
- const { isFocusVisible, isFocused, focusProps } = useFocusRing (props )
66
+ To use React Aria's render props, including the ` className ` , ` style ` , and ` children ` functions, create a wrapper component and pass that to ` createLink ` .
90
67
91
- return (
92
- <a
93
- { ... mergeProps (linkProps , hoverProps , focusProps , props )}
94
- ref = { ref }
95
- data-hovered = { isHovered || undefined }
96
- data-pressed = { isPressed || undefined }
97
- data-focus-visible = { isFocusVisible || undefined }
98
- data-focused = { isFocused || undefined }
99
- />
100
- )
101
- },
102
- )
68
+ ``` tsx
69
+ import { createLink } from ' @tanstack/react-router'
70
+ import { Link as RACLink , type LinkProps } from ' react-aria-components'
103
71
104
- const CreatedLinkComponent = createLink (RACLinkComponent )
72
+ interface MyLinkProps extends LinkProps {
73
+ // your props
74
+ }
105
75
106
- export const CustomLink: LinkComponent <typeof RACLinkComponent > = (props ) => {
107
- return <CreatedLinkComponent preload = { ' intent' } { ... props } />
76
+ function MyLink(props : MyLinkProps ) {
77
+ return (
78
+ <RACLink
79
+ { ... props }
80
+ style = { ({ isHovered }) => ({
81
+ color: isHovered ? ' red' : ' blue' ,
82
+ })}
83
+ />
84
+ )
108
85
}
86
+
87
+ export const Link = createLink (MyLink )
109
88
```
110
89
111
90
### Chakra UI example
0 commit comments