# @sharyn/hooks

> ## useStateObject

Latest version **1.1.1** (published 2019-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sharyn/hooks
pnpm add @sharyn/hooks
yarn add @sharyn/hooks
bun add @sharyn/hooks
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-09-07 |
| First published | 2019-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Maintainers | sharyn |

## Links

- npm: https://www.npmjs.com/package/@sharyn/hooks
- Repository: https://github.com/sharynjs/sharyn
- Homepage: https://github.com/sharynjs/sharyn/tree/master/packages/hooks
- Issues: https://github.com/sharynjs/sharyn/issues
- npm.io page: https://npm.io/package/@sharyn/hooks

## Dependencies (2)

- [lodash.merge](https://npm.io/package/lodash.merge.md) 4.6.2
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) 4.5.0

## Recent versions

- 1.1.1 (latest) — 2019-09-07
- 1.0.1 — 2019-09-05
- 1.0.0 — 2019-08-28
- 0.1.0 — 2019-08-28

## README

# 🌹 @sharyn/hooks

## useStateObject

```jsx
import { useStateObject } from '@sharyn/hooks'
// or import useStateObject from '@sharyn/hooks/useStateObject'

const Cmp = () => {
  const { set: setField, get: getField, getAll: getFields } = useStateObject()

  return (
    <>
      <input
        name="firstname"
        onChange={e => setField('firstname', e.target.value)}
        value={getField('firstname') || ''}
      />
      <input
        name="lastname"
        onChange={e => setField('lastname', e.target.value)}
        value={getField('lastname') || ''}
      />
      <button onClick={() => console.log(getFields())}></button>
    </>
  )
}
```

### API

**`useStateObject(initialStateObject)`**: Pass an initial object to the hook, defaults to `{}`.

**`getAll()`**: Returns the entire state object

**`get(key)`**: Returns the value for the key

**`set(key, value)`**: Sets the value for the key

**`setAll(obj)`**: Replace the entire state object

**`del(key)`**: Deletes the value for the key

**`clear()`**: Resets the state object to `{}`

**`merge(obj)`**: Merge the state object deeply with an other object using Lodash's [merge](https://www.npmjs.com/package/lodash.merge).

**`assign(obj)`**: Merge the state object shallowly with an other object using `Object.assign()`.

<p align="center">
  This package is part of <a href="https://github.com/sharynjs/sharyn"><b>Sharyn</b></a>, a collection of utilities and helpers.
</p>

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