# @rcp/use.uncontrolled

[![NPM version](https://img.shields.io/npm/v/@rcp/use.uncontrolled.svg?style=flat-square)](https://www.npmjs.com/package/@rcp/use.uncontrolled)
[![NPM Downloads](https://img.shields.io/npm/dm/@rcp/use.uncontrolled.svg?style=flat-square&maxAge=43200)](https://www.npmjs.com/package/@rcp/use.uncontrolled)

Make props.value piped to state, and exposes `onChange`, make react component is **uncontrolled & controlled**

## Installation

```bash
npm install @rcp/use.uncontrolled
# or use yarn
yarn add @rcp/use.uncontrolled
```

## Usage

```javascript
import useUncontrolled from '@rcp/use.uncontrolled'
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### useUncontrolled

#### Parameters

- `value` {T} - Piped value
- `defaultValue` {T} - Initialize value firstly
- `onChange` {(value: T) => void} - Bind `onChange` handler when value updating
- `useEffect` {typeof React.useLayoutEffect}
- `eq` {(a: T, b: T) => boolean}

#### Examples

```javascript
function Input({ value, onChangeValue, defaultValue }) {
  const [valueState, setValue] = useUncontrolled({ value, onChange: onChangeValue, defaultValue })

  return <input type="text" value={valueState} onChange={(evt) => setValue(evt.target.value)} />
}
```

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** `[T, ((value: T) => T | T) => void]`

## Related

## Authors

This library is written and maintained by imcuttle, <a href="mailto:moyuyc95@gmail.com">moyuyc95@gmail.com</a>.

## License

MIT
