Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-addons-text-content with all npm packages installed. Try it out:

var reactAddonsTextContent = require("react-addons-text-content")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-addons-text-content v0.0.4

Like DOM API's `Node.textContent` and it works in React Element

version Build Status Coverage

react-addons-text-content

Like DOM API's Node.textContent and it works in React Element

Install

$ npm install --save react-addons-text-content

Usage

import textContent from 'react-addons-text-content'
 
render() {
  const {children} = this.props
  const text = textContent(children)
  
  return (...)
}

Examples

test('should be got text `Hello World`', assert => {
  const Com =
      <div>
        <h1>Hello</h1> World
      </div>

  assert.is(textContent(Com), `Hello World`)
})
test('array children', assert => {
  const Com = (
    <div>
      <h1>Hello</h1> World
      {
        ['a', <h2>b</h2>]
      }
    </div>
  )
  
  assert.is(textContent(Com), `Hello Worldab`)
})
test('array component', assert => {
  const Com = (
    [
      <h1>a</h1>, 'b', 'c',
      <div>
        <h2>x</h2>y
      </div>
    ]
  )

  assert.is(textContent(Com), `abcxy`)
})

API

textContent([React Element])

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free