Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/quisido/react-innertext

Returns the innerText of a React JSX object.
https://github.com/quisido/react-innertext

babel babeljs chai es6 innerhtml innertext javascript js mocha npm npm-module npm-package react reactjs travis travis-ci travisci webpack

Last synced: about 2 months ago
JSON representation

Returns the innerText of a React JSX object.

Awesome Lists containing this project

README

        

# React innerText

[![version](https://img.shields.io/npm/v/react-innertext.svg)](https://www.npmjs.com/package/react-innertext)
[![minzipped size](https://img.shields.io/bundlephobia/minzip/react-innertext.svg)](https://www.npmjs.com/package/react-innertext)
[![downloads](https://img.shields.io/npm/dt/react-innertext.svg)](https://www.npmjs.com/package/react-innertext)

Returns the innerText of a React JSX object, similar to the innerText property
of DOM elements.

## Install

* `npm install react-innertext` or
* `yarn add react-innertext`

## Use

### Client-Side Rendering (ES6)

```JS
import innerText from 'react-innertext';
innerText(


Hello world!
I am years old!

) // 'Hello world! I am 3 years old!'
```

### Server-Side Rendering (CommonJS)

```JS
const innerText = require('react-innertext');
innerText(


Hello world!
I am years old!

) // 'Hello world! I am 3 years old!'
```

### Real World Example

In the below example, the `title` attribute of the `` element sanitizes the
`children` prop. This allows the children to contain HTML or other React
Elements, while providing a safe, plain text string for the `title`.

```JS
function MyTableHeader() {
return (



Username




);
}

// title="Username"
function MyTableHeaderCell({ children }) {
return (

);
}
```

## Sponsor 💗

If you are a fan of this project, you may
[become a sponsor](https://github.com/sponsors/CharlesStover)
via GitHub's Sponsors Program.