Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/intuit/text-provider
- Owner: intuit
- License: mit
- Created: 2018-12-14T04:18:54.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-26T06:08:18.000Z (3 months ago)
- Last Synced: 2024-10-29T23:07:37.462Z (3 months ago)
- Topics: hacktoberfest, node, npm, provider, react, react-js
- Language: JavaScript
- Homepage:
- Size: 675 KB
- Stars: 24
- Watchers: 4
- Forks: 21
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
text-provider
A component which provides all the string constants using provider pattern
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.