Skip to content

A template utility to replace string with jsx elements.

Notifications You must be signed in to change notification settings

nobuti/retemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

retemplate

A template utility to replace strings with jsx elements.

Given a string, replace every {key} with the data[key] passed. This can be a function returning a string or a raw string. The result will be an array of strings mixed with jsx elements. The primary use case is similar to using String.prototype.replace except for React.

Usage

import template from '@nobuti/retemplate'

render() { 
  return (
    <div>
      {template("hola {mundo} cruel {mundo} foo {wadus}", { 
        mundo: () => <span>mundo</span>, 
        wadus: "foo" 
      })}
    </div>
  )
}

About

A template utility to replace string with jsx elements.

Resources

Stars

Watchers

Forks

Packages

No packages published