# react-configurable

> Provide config to props easily and efficiently

Latest version **0.2.1** (published 2018-09-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-configurable
pnpm add react-configurable
yarn add react-configurable
bun add react-configurable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-09-20 |
| First published | 2018-09-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 270.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ricky Harkins |
| Maintainers | ricketysplit |

## Links

- npm: https://www.npmjs.com/package/react-configurable
- Repository: https://github.com/ricketysplit/react-configurable
- Homepage: https://github.com/ricketysplit/react-configurable#readme
- Issues: https://github.com/ricketysplit/react-configurable/issues
- npm.io page: https://npm.io/package/react-configurable

## Dependencies (4)

- [react](https://npm.io/package/react.md) ^16.4.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [react-dom](https://npm.io/package/react-dom.md) ^16.4.2
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.2

## Recent versions

- 0.2.1 (latest) — 2018-09-20
- 0.2.0 — 2018-09-20
- 0.1.2 — 2018-09-17
- 0.1.1 — 2018-09-17
- 0.1.0 — 2018-09-17

## README

# React-Configurable

`react-configurable` uses `React.Context` to allow easy access and use of application wide config values.

## Installation
```
npm install react-configurable --save
```
react-configurable requires React > 16

## Examples

### ConfigProvider

Usage requires the application to be wrapped in a `ConfigProvider` component

```jsx
import {ConfigProvider} from 'react-configurable';

const config = {
    mockValue: 'value1',
    nested: {
        mockNestedValue: 'value3',
    },
    mockHide: true,
    mockHide2: 'value2'
}

class ConfigExample extends React.Component {
    render() {
        return <ConfigProvider config={config}>
                    <App />
               <ConfigProvider>;
    }
}

ReactDOM.render(<ConfigExample />, document.getElementById('container'));
```

### ConfigEnhancer

Once the application is wrapper in `ConfigProvider`, values can be passed through `ConfigEnhancer` using prop keys

```jsx
import {ConfigEnhancer} from 'react-configurable';

const Example = ({mockValue}) => <div>{mockValue}</div>;

// Pass values to Example through ConfigEnhancer
export default <ConfigEnhancer mockValue><Example /></ConfigEnhancer>
```

If the config has nested values, pass the dot notated path to the prop key

```jsx
import {ConfigEnhancer} from 'react-configurable';

const Example = ({mockValue}) => <div>{mockValue}</div>;

// Pass values to Example through ConfigEnhancer
export default <ConfigEnhancer mockValue="nested.mockNestedValue"><Example /></ConfigEnhancer>
```

### ConfigHide / ConfigShow

Also provided are simple approaches to showing and hiding components based on config

```jsx
import {ConfigHide} from 'react-configurable';

export default <ConfigHide mockHide><div>Should be hidden</div></ConfigHide>
```

If `mockHide` in the config is true, then the component is hidden.

One difference from `ConfigEnhancer` is that if an actual value is passed into a prop, it is used for an equality check instead of passing the value;

So in the following example, `react-configurable` will compare the config value of `mockHide` to the value passed into `ConfigHide`

```jsx
import {ConfigHide} from 'react-configurable';

// This will only be hidden if the config value of mockHide equals false
export default <ConfigHide mockHide={false}><div>Should be hidden</div></ConfigHide>
```

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