@weprovide/react-link-renderer

1.0.9 • Public • Published

react-link-renderer

This package will enable you to render a custom link component within a component library for example.

Install

yarn add @weprovide/react-link-renderer

Example usage using a custom link renderer (for example using next/link)

import {LinkRenderer, LinkRendererProvider, LinkRendererProps} from '@weprovide/react-link-renderer';
import Link from "next/link";

const nextLinkRenderer = ({ href, extraOptions, children }: LinkRendererProps) => {
    return (
        <Link href={href} {...extraOptions}>
            <a>{children}</a>
        </Link>
    );
}

Surround your main app with a LinkRendererProvider

<LinkRendererProvider linkRenderer={nextLinkRenderer}>
    <App />
</LinkRendererProvider>

Now you can use the LinkRenderer component inside your component library to render a link

<LinkRenderer 
    href="/page-1" 
    extraOptions={{
        prefetch: false, // You can add any option you want and use it in your custom link renderer
    }}
>
    Go to page 1
</LinkRenderer>

Readme

Keywords

none

Package Sidebar

Install

npm i @weprovide/react-link-renderer

Weekly Downloads

51

Version

1.0.9

License

ISC

Unpacked Size

7.6 kB

Total Files

5

Last publish

Collaborators