An open API service indexing awesome lists of open source software.

https://github.com/potty/react-anchorme

⚓️ React component using Anchorme.js to detect urls and emails in a text and converts them into clickable HTML links.
https://github.com/potty/react-anchorme

links react typescript

Last synced: 6 months ago
JSON representation

⚓️ React component using Anchorme.js to detect urls and emails in a text and converts them into clickable HTML links.

Awesome Lists containing this project

README

          

# react-anchorme

![](https://github.com/potty/react-anchorme/workflows/Tests/badge.svg) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-anchorme)](https://bundlephobia.com/result?p=react-anchorme) ![npm](https://img.shields.io/npm/dm/react-anchorme)

React component using [Anchorme.js](https://github.com/alexcorvi/anchorme.js) to detect urls and emails in a text and converts them into clickable HTML links.

## 🚀 Installation

```bash
# npm
npm i react-anchorme

# Yarn
yarn add react-anchorme

# pnpm
pnpm add react-anchorme
```

## 🖲 Usage

### Basic usage

Component takes string as a children, detects urls, emails, IP addresses in it and replaces them with clickable HTML links.

```jsx static
import React from 'react'
import { Anchorme } from 'react-anchorme'

const SomeComponent = () => {
return (
Lorem ipsum http://example.loc dolor sit amet
)
}
```

### Custom props

You can set custom anchor props that are applied to every link created by the component.

```jsx static
import React from 'react'
import { Anchorme } from 'react-anchorme'

const SomeComponent = () => {
return (

Lorem ipsum http://example.loc dolor sit amet

)
}
```

### Truncate

You can truncate link text by setting up `truncate` prop:

```jsx static
import React from 'react'
import { Anchorme } from 'react-anchorme'

const SomeComponent = () => {
return (

Lorem ipsum example.com dolor sit amet

)
}
```

### Custom link component

You can set custom link component that is rendered instead of default anchor element.

```jsx static
import React from 'react'
import { Anchorme, LinkComponentProps } from 'react-anchorme'

const CustomLink = (props: LinkComponentProps) => {
return (



)
}

const SomeComponent = () => {
return (

Lorem ipsum http://example.loc dolor sit amet

)
}
```