createLinkWithAdapter
functionAdvanced
Builds a link component bound to one adapter, which renders without any LinkProvider above it.
import { createLinkWithAdapter } from '@salla.sa/twilight-theme-engine/providers';In plain words
Sometimes a link must render the same way whatever provider is, or is not, above it: in an isolated widget or a test. createLinkWithAdapter(adapter) returns such a component.
Signature
function createLinkWithAdapter(adapter: LinkAdapter): React.ComponentType<LinkProps>
Example
app/components/RouterLink.tsx
import { createLinkWithAdapter } from '@salla.sa/twilight-theme-engine/providers';
import { TanStackLinkAdapter } from '@salla.sa/twilight-theme-engine/tanstack';
// Always TanStack Router's anchor, even where no LinkProvider is mounted.
export const RouterLink = createLinkWithAdapter(TanStackLinkAdapter);
How it behaves
The returned component is
(props) => createElement(adapter, props): unlike the engineLink, it does not defaulttofromhrefand does not adddata-spa-link.It is a plain function component, not
forwardRef. On React 19, which passesrefas an ordinary prop, arefstill reaches the adapter.
Gotchas
TanStackLinkAdapterreads the router'slocaleparam, so a link bound to it still needs a TanStack router above it, even without aLinkProvider.
Related
Source and docs
- Engine source:
packages/theme-engine/src/providers/LinkProvider.tsx