npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-link-provider

v0.3.0-alpha.2

Published

A lightweight utility for providing a consistent, framework-agnostic link component across React applications.

Downloads

29

Readme

React Link Provider

🔗 React Link Provider

A lightweight utility for providing a consistent, framework-agnostic link component across React applications.

⚖️ License

Licensed under the MIT license and is free for private or commercial projects.

✨ Introduction

The react-link-provider library is a lightweight, framework-agnostic context for managing link behavior across React apps. It provides a unified way for components to render consistent navigation elements, no matter which routing library is used, while remaining fully compatible with server-side rendering, theming, and flexible context composition.

⚠️ Note:
This package is currently in alpha (0.3.0) and the API may change.
Feedback and bug reports are welcome. For production use, thorough testing and dependency version pinning are recommended.

💡 Rationale

In many React applications, components need to render links — but not every project uses the same routing system. For example:

  • One app might use react-router-dom, while another uses Next.js or Remix.
  • Some UI components might need to work without any router (e.g., in Storybook or documentation).
  • Design systems or shared component libraries might not require a hard dependency on any routing library.
  • Link logic may need to work seamlessly with server-side rendering (SSR) and theming solutions.

This library solves these challenges by:

  1. Enabling injection of any link component at the top level of the application.
  2. Providing a simple hook that always returns the correct link component from context.
  3. Gracefully falling back to a standard anchor element when no router is used.

This approach is ideal for shared UI libraries, SSR environments, and applications that require routing flexibility without coupling to a specific framework.

📥 Installation

Install the package using any preferred dependency management tool:

# npm
npm install react-link-provider

# or pnpm
pnpm add react-link-provider

# or yarn
yarn add react-link-provider

🚀 Getting Started

Wrap the application in <LinkProvider> and pass a LinkComponent — for example, from react-router-dom:

import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { LinkProvider } from 'react-link-provider';
import { BrowserRouter, Link as RouterLink } from 'react-router-dom';

import App from './App.tsx';

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <BrowserRouter>
      <LinkProvider LinkComponent={RouterLink}>
        <App />
      </LinkProvider>
    </BrowserRouter>
  </StrictMode>
);

Or a custom React component can be used as the link. This allows integration with design system links, styled anchor tags, or any other link component with a compatible props shape:

import { ReactNode } from 'react';

type CustomLinkProps = {
  to: string;
  children: ReactNode;
  // Add any other props required by the design system
};

export const CustomLink = ({ to, children, ...rest }: CustomLinkProps) => {
  return (
    <a
      href={to}
      style={{ color: 'red', textDecoration: 'underline' }}
      {...rest}
    >
      {children}
    </a>
  );
};

The custom component can then be provided via <LinkProvider>:

<LinkProvider LinkComponent={CustomLink}>
  <App />
</LinkProvider>

This setup works with any compatible React component, including routing library links, custom UI kit components, or simple styled anchor elements.

📖 Usage

The useLink hook provides access to the LinkComponent set in context. If no provider is defined, it falls back to a native <a> element.

import { useLink } from 'react-link-provider';
import { Route, Routes } from 'react-router-dom';

const Home = () => {
  const Link = useLink();

  return (
    <div>
      <h1>Home</h1>
      <Link to="/about">Go to About</Link>
    </div>
  );
};

const About = () => {
  const Link = useLink();

  return (
    <div>
      <h1>About</h1>
      <Link to="/">Back Home</Link>
    </div>
  );
};

export default function App() {
  return (
    <Routes>
      <Route path="/" element={<Home />} />
      <Route path="/about" element={<About />} />
    </Routes>
  );
}