0.1.14 • Published 5 years ago

@render-props/paragraphs v0.1.14

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Paragraphs

A function as child component which provides an interface for creating paragraphs with line breaks from raw text with \n new lines. The default render child is:

const defaultParagraph = props => <p key={props.key} children={props.text}/>

Installation

yarn add @render-props/paragraphs or npm i @render-props/paragraphs


Usage

import Paragraphs from '@render-props/paragraphs'


function MyParagraphs ({text}) {
  return (
    <Paragraphs text={text}>
      {({key, text, n, count}) => (
        <p
          key={key}
          className={n === count - 1 ? 'margin--b0' : 'margin--b3'}
          children={text}
        />
      )}
    </Paragraphs>
  )
}

MyParagraphs({text: 'foo\n\nbar\n\nbaz\nboz'})

/*
Outputs:
<p className='margin--b3'>
  foo
</p>
<p className='margin--b3'>
  bar
</p>
<p className='margin--b0'>
  baz
  <br/>
  boz
</p>
*/

Props

  • text {string}
    • the text you want to turn into paragraphs with line breaks

Render Props

State

  • text (value <!== undefined>)
    • the text in this paragraph with line breaks included
  • n
    • the current paragraph index
  • count
    • the total number of paragraphs
0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago