Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Layout and type

LinkProvider

Makes every Stylhero link (Link, Breadcrumbs, SideNav, AppBar, ListItem) render your router's link. In Next.js: <LinkProvider component={NextLink}> in app/layout.tsx.

import { LinkProvider } from "@stylhero/ui";

Example

Code
import { useState, type ReactNode } from "react";
import { Button, LinkProvider, Stack, Text } from "@stylhero/ui";

function LinkProviderExample() {
  // In Next.js: <LinkProvider component={NextLink}> in your root layout.
  // Every Stylhero link (Button href, Link, menus, navs) then uses it.
  const [pushed, setPushed] = useState<string | null>(null);
  const RouterLink = ({ href, ...props }: { href: string; children?: ReactNode; className?: string }) => (
    <a href={href} {...props} onClick={(e) => { e.preventDefault(); setPushed(href); }} />
  );
  return (
    <Stack gap={2} align="flex-start">
      <LinkProvider component={RouterLink}>
        <Button href="/builds">Goes through your router</Button>
      </LinkProvider>
      <Text variant="small" tone="muted">{pushed ? `router.push("${pushed}")` : "Click the button"}</Text>
    </Stack>
  );
}

Props

PropTypeDefaultDescription
children required ReactNode -
component required LinkLike -

Types

type LinkLike = ElementType;

Generated from src/link.tsx. Something wrong or missing? Open an issue.