Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/intuit/text-provider

A react component which provides all the string constants using provider pattern
https://github.com/intuit/text-provider

hacktoberfest node npm provider react react-js

Last synced: 5 days ago
JSON representation

A react component which provides all the string constants using provider pattern

Awesome Lists containing this project

README

        



text-provider



A component which provides all the string constants using provider pattern




CircleCI


npm


All Contributors


npm

Text provider is a library to place all the string constants of an application in a single place and use them inside the components in a memory friendly way.

It provides two components:

1. [TextProvider](src/TextProvider.jsx)
2. [FormattedMessage](src/FormattedMessage.jsx)

## Install

```bash
npm i text-provider
```

## Usage

1. Import the string constants required for the particular presentational component:

```javascript
const sampleText = require("src/nls/sample-text.json");
```

2. Use the [TextProvider](src/TextProvider.jsx) to make it available for all the components:

```jsx

```

3. Use it inside the presentational component:

```jsx

```

```jsx
const randomId = "Random Id";
const values = {
"valueToBeInjected": "Random Value"
};

```

Works like a format string also. Example JSON:

```json
{
"Random Id": "Random Text Returns {valueToBeInjected} for each text)"
}
```

Then ``${valueToBeInjected}`` gets replaced with the value specified in `values`.

Make sure that a string by the same `id` exists in the JSON file.