# @automattic/interpolate-components

> Convert strings into structured React components.

Latest version **1.2.2** (published 2026-06-22) · GPL-2.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @automattic/interpolate-components
pnpm add @automattic/interpolate-components
yarn add @automattic/interpolate-components
bun add @automattic/interpolate-components
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2026-06-22 |
| First published | 2021-11-09 |
| Weekly downloads | 0 |
| License | GPL-2.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 25 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12651 |
| Author | Automattic Inc. |
| Maintainers | macbre, yuliyan, mjangda, matticbot, a8c, blowery, ehg_, sgomes, tyxla, saroshaga, nejclovrencic, sirbrillig, chriszarate, robersongomes, johngodley, jeherve, daledupreez-a8c, t2dw4t, luismulinari, andrea-sdl, elazzabi, fmfernandes, sirreal, wwa, chihsuan, manzoorwanijk, msurdi-a8c, newspack-npm, dsmartg, kthai15, bgrgicak, robertsreberski_a8c, artpi, gmjuhasz, kat3samsin, brunobasto, dhenridev, mrmurphy, wpvip-bot, etobiesen, alshakero, arthur791004, dilirity, mehmoodak, natalia.vidal, ivan.ottinger, anandnalya, arcangelinis, retrofox, fredrikekelund, chriskmnds, oandregal, galatanovidiu, kangzj, _mirka_, aduth, ebuccelli |

## Links

- npm: https://www.npmjs.com/package/@automattic/interpolate-components
- Repository: https://github.com/Automattic/wp-calypso
- Homepage: https://github.com/Automattic/wp-calypso/tree/HEAD/packages/interpolate-components#readme
- Issues: https://github.com/Automattic/wp-calypso/issues
- npm.io page: https://npm.io/package/@automattic/interpolate-components

## Recent versions

- 1.2.2 (latest) — 2026-06-22
- 1.2.1 — 2022-03-17
- 1.2.0 — 2021-12-03
- 1.1.2 — 2021-11-09

## README

# 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 a string without using the hack of `dangerouslySetInnerHTML()`.

## Module Footprint

`interpolateComponents` takes a single options object as an argument and returns a React element 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** (optional) An object with components assigned to named attributes. If not provided, `mixedString` is returned.
- **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.

## Component tokens

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.

```js
// example component token syntax
const example = '{{link}}opening and closing syntax example{{/link}}';
const example2 = 'Here is a self-closing example: {{input/}}';
```

## Example Usage

```jsx
import interpolateComponents from '@automattic/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>
```

---
_Source: https://npm.io/package/@automattic/interpolate-components · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
