Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

react-addons-text-content

0.0.4 • Public • Published

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])

install

npm i react-addons-text-content

Downloadsweekly downloads

12,778

version

0.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability