1.0.2 • Published 5 years ago

react-string-template v1.0.2

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

react-string-template

react-string-template is simple string template with react

install

npm i --save react-string-template

  <ReactStringTemplate
    str={"{name} is a series of {foo} novels written by British author {author} in {yeah}."}
    renderNoMatch={()=>'not match'}
    values={{
      name: <a href="https://www.google.com/search?q=Harry Potter" key='potter'>Harry Potter</a>,  // Don't forget write key
      foo: 'fantasy',
      bar: 'novels',
      author: 'J. K. Rowling',
      yeah: 1997,
    }} >
    {(children)=><div>{children}</div>}
  </ReactStringTemplate>

  //Harry Potter is a series of fantasy novels written by British {author} J. K. Rowling in 1997.
  // add click event
  <ReactStringTemplate
    str={"{charmName} Charm"}
    values={{
      charmName: (
        <span
          key='patronus'
          onClick={()=>alert('Patronus!')}>
          Patronus
        </span>
      ),
    }} >
    {(children)=><div>{children}</div>}
  </ReactStringTemplate>
  // render no Match
  <ReactStringTemplate
    str={"I am {name}"}
    renderNoMatch={()=>'not match'} >
    {(children)=><div>{children}</div>}
  </ReactStringTemplate>

  //I am not match

If you don't need escape use {{escape}}

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago