Socket
Socket
Sign inDemoInstall

interpolate-components

Package Overview
Dependencies
3
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    interpolate-components

A module to turn strings into structured React components without dangerouslyInsertInnerHTML()


Version published
Weekly downloads
9.7K
increased by38.02%
Maintainers
1
Install size
10.1 MB
Created
Weekly downloads
 

Changelog

Source

1.0.3

  • Add changelog and tweak readme.

Readme

Source

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().

NPM

Usage

The Interpolate-Components module exports a function which takes a single options object as an argument. The attributes of that object 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.

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 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 component token syntax
var example = '{{link}}opening and closing syntax example{{/link}}',
    example2 = 'Here is a self-closing example: {{input/}}';

Example usage:

/** @jsx React.DOM */
import interpolateComponents from 'interpolate-components';
const children = interpolateComponents( {
        mixedString: 'This is a {{em}}fine{{/em}} example.',
        components; { em: <em /> }
    } );
const jsxExample = <p>{ children }</p>;
// when injected into the doc, will render as:
// <p>This is a <em>fine</em> example.</p>

Keywords

FAQs

Last updated on 08 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc