interpolate-components
Advanced tools
Comparing version
# Changelog | ||
## 1.0.4 | ||
* Readme and package description edits. | ||
## 1.0.3 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "interpolate-components", | ||
"version": "1.0.3", | ||
"description": "A module to turn strings into structured React components without dangerouslyInsertInnerHTML()", | ||
"version": "1.0.4", | ||
"description": "Convert strings into structured React components.", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
Interpolate-Components | ||
====================== | ||
Interpolate-Components allows us to work with structured markup as strings and then hydrate them into a tree of React components. This is particularly useful for internationalizing strings, where a sentence or paragraph containing structured markup should be translated as a single entity. This module allows us to _interpolate_ components into the string without using the hack of `_dangerouslySetInnerHTML()`. | ||
Interpolate-Components allows us to work with structured markup as strings and then hydrate them into a tree of React components. This is particularly useful for internationalizing strings, where a sentence or paragraph containing structured markup should be translated as a single entity. This module allows us to _interpolate_ components into a string without using the hack of `dangerouslySetInnerHTML()`. | ||
[](https://nodei.co/npm/interpolate-components/) | ||
## Usage | ||
## Module Footprint | ||
The Interpolate-Components module exports a function which takes a single options object as an argument. The attributes of that object are: | ||
Interpolate-Components takes a single options object as an argument and returns a React component containing structured descendent components which can be rendered into a document. The option attributes are: | ||
### mixedString | ||
A string that contains component tokens to be interpolated | ||
### components | ||
An object with components assigned to named attributes | ||
### throwErrors | ||
Whether errors should be thrown (as in pre-production environments) or we should more gracefully return the un-interpolated original string (as in production). This is optional and is false by default. | ||
- **mixedString** A string that contains component tokens to be interpolated | ||
- **components** An object with components assigned to named attributes | ||
- **throwErrors** (optional) Whether errors should be thrown (as in pre-production environments) or we should more gracefully return the un-interpolated original string (as in production). This is optional and is false by default. | ||
The Interpolate-Components module takes these input options and returns a React component containing structured descendent components that can be injected into a React element. | ||
## Component tokens | ||
@@ -29,3 +26,3 @@ Component tokens are strings (containing letters, numbers, or underscores only) wrapped inside double-curly braces and have an opening, closing, and self-closing syntax, similar to html. | ||
Example usage: | ||
## Example Usage | ||
@@ -37,3 +34,3 @@ ```js | ||
mixedString: 'This is a {{em}}fine{{/em}} example.', | ||
components; { em: <em /> } | ||
components: { em: <em /> } | ||
} ); | ||
@@ -44,1 +41,9 @@ const jsxExample = <p>{ children }</p>; | ||
``` | ||
## Testing | ||
```sh | ||
# install dependencies | ||
npm install | ||
# run tests | ||
make test | ||
``` |
40982
0.06%47
11.9%