Skip to content

Instantly share code, notes, and snippets.

@baumandm
Created October 19, 2020 20:35
Show Gist options
  • Save baumandm/1e2d87cb47e6a02191abea3686593f20 to your computer and use it in GitHub Desktop.
Save baumandm/1e2d87cb47e6a02191abea3686593f20 to your computer and use it in GitHub Desktop.

Tiny wrapper component for [React-linkify](https://github.com/tasti/react-linkify to stylistically fit with Chakra-UI.

npm install --save react-linkify
npm install --save-dev @types/react-linkify

Instead of using the <Linkify> component provided by React-linkify, import the custom wrapper provided below.

import { Linkify } from '@components/linkify/linkify';

...

<Linkify>...</Linkify>

Adapted from this comment.

import { Link } from '@chakra-ui/core';
import React from 'react';
import ReactLinkify from 'react-linkify';
// This function creates the desired Link components, based on the Chakra-UI `Link`
// Customize as needed!
const componentDecorator = (href, text, key) => (
<Link href={href} key={key} isExternal={true}>
{text}
</Link>
);
export const Linkify = (props) => {
return <ReactLinkify {...props} componentDecorator={componentDecorator} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment