# use-reselect

> Hooks friendly reselect

Latest version **0.0.2** (published 2019-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-reselect
pnpm add use-reselect
yarn add use-reselect
bun add use-reselect
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-04-16 |
| First published | 2019-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.5.0 |
| Dependencies | 1 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | theKashey |
| Maintainers | kashey |
| Keywords | reselect, hooks, memoization |

## Links

- npm: https://www.npmjs.com/package/use-reselect
- Repository: https://github.com/theKashey/useReselect
- Homepage: https://github.com/theKashey/useReselect#readme
- Issues: https://github.com/theKashey/useReselect/issues
- npm.io page: https://npm.io/package/use-reselect

## Dependencies (1)

- [kashe](https://npm.io/package/kashe.md) ^0.2.0

## Recent versions

- 0.0.2 (latest) — 2019-04-16
- 0.0.1 — 2019-04-16

## README

useReselect
===

__DEVELOPMENT PREVIEW__

This is a fork of [reselect](https://github.com/reduxjs/reselect), mixed with [kashe](https://github.com/theKashey/kashe) and React `hooks`.

# API
API is 100% compatible with Reselect.

- `createSelector` - as seen in reselect

# Hooks
## useReselect
- `useReselect(cb)` - selection runner. __All__ selectors inside would be executed inside a sandbox, making result instance bound.
```js
const getUser = createSelector((state: any, userId: string) => (
  state.users[userId] + `:${recomputations++}`
), i => i);

const User = ({userId, tick}) => {
  const userName = useReselect(() => getUser(state, userId));
  return <span>user({userId}): {userName}</span>
}

// this would work
<>
 <User userId="user1" />
 <User userId="user2" /> 
</>


// this would not, getUser still could hold only one result
const DoubleUser = ({userId, tick}) => {
  const [u1, u2] = useReselect(() => [getUser(state, 'a'),getUser(state, 'b')]);
  return <span>{u1} - {u2}</span>
}
```

## useReReselect
- `useReReselect(cb)` - selection runner. __Every__ selector inside would be executed in a personal sandbox, making it instance bound
```js
// every selector would be executed in a personal sandbox
const DoubleUser = ({userId, tick}) => {
  const [u1, u2] = useReReselect(() => [getUser(state, 'a'),getUser(state, 'b')]);
  return <span>{u1} - {u2}</span>
}
```

## Running selectors without React
```js
// run it once
const [u1, u2] = useReReselect(() => [getUser(state, 'a'),getUser(state, 'b')]);
// get "hooks"
const stack = useReReselect.getStack();

// run it with "custom hooks"
const [u1, u2] = useReReselect(() => [getUser(state, 'a'),getUser(state, 'b')], stack);
```

## Sharing results
All selectors are double memoized, letting _shareable_ data be shared.

# License
MIT

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