# @app-elements/use-mapped-state

> A (P)React hook to map part of global state to a child component.

Latest version **1.0.0** (published 2020-06-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @app-elements/use-mapped-state
pnpm add @app-elements/use-mapped-state
yarn add @app-elements/use-mapped-state
bun add @app-elements/use-mapped-state
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-06-24 |
| First published | 2019-06-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Input Logic Team |
| Maintainers | adriaanwm, coryschadt, staydecent, trustfall |
| Keywords | react, react-component, preact, component, hook, ui |

## Links

- npm: https://www.npmjs.com/package/@app-elements/use-mapped-state
- Repository: https://github.com/inputlogic/elements
- Homepage: https://github.com/inputlogic/elements#readme
- Issues: https://github.com/inputlogic/elements/issues
- npm.io page: https://npm.io/package/@app-elements/use-mapped-state

## Alternatives

- [@progress/kendo-ooxml](https://npm.io/package/@progress/kendo-ooxml.md) — 152.1K weekly downloads
- [@progress/kendo-react-ripple](https://npm.io/package/@progress/kendo-react-ripple.md) — 8.0K weekly downloads
- [@progress/kendo-react-orgchart](https://npm.io/package/@progress/kendo-react-orgchart.md) — 4.3K weekly downloads
- [@praxisui/dynamic-fields](https://npm.io/package/@praxisui/dynamic-fields.md) — 2.4K weekly downloads
- [@mesalvo/react-ui](https://npm.io/package/@mesalvo/react-ui.md) — 1.7K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-06-24
- 1.0.0-alpha.0 — 2020-06-23
- 0.3.2 — 2020-03-05
- 0.3.1 — 2020-01-22
- 0.3.0 — 2019-10-16
- 0.2.1 — 2019-10-11
- 0.2.0 — 2019-08-20
- 0.1.1 — 2019-06-11

## README

# useMappedState

useMappedState maps values from the provided (atom/Redux) store and keeps your Component synced with any changes to those mapped values.

## Installation

`npm install --save @app-elements/use-mapped-state`

## Usage

```javascript
import { useMappedState } from '@app-elements/use-mapped-state'
import createStore from 'atom'

const store = createStore([], { count: 0 })

// Here is a simple view that expects a `count` value
// form the global state.
const Stateful = (props) => {
  // `mapper` is a function that is given the entire state object from your store.
  // Your job is to return the portion of that state object that this Component
  // is concerned with.
  const mapper = ({ count }) => ({ count })
  const { count } = useMappedState(store, mapper)
  return (
    <p>Count: {count}</p>
  )
}
```

## Props

| Prop                   | Type       | Default       | Description         |
|------------------------|------------|---------------|---------------------|
| **`store`**            | _Object_   | _None_        | An (atom) store instance
| **`mapper`**           | _Function_ | _None_        | A function that accepts `(state)` and returns an object

---
_Source: https://npm.io/package/@app-elements/use-mapped-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
