# recoil-types

> To a second type parameter to selector of Recoil

Latest version **0.2.0** (published 2021-04-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install recoil-types
pnpm add recoil-types
yarn add recoil-types
bun add recoil-types
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-04-19 |
| First published | 2021-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sanonz |
| Maintainers | sanonz |
| Keywords | recoil |

## Links

- npm: https://www.npmjs.com/package/recoil-types
- Repository: https://github.com/sanonz/recoil-types
- Issues: https://github.com/sanonz/recoil-types/issues
- npm.io page: https://npm.io/package/recoil-types

## Recent versions

- 0.2.0 (latest) — 2021-04-19
- 0.1.0 — 2021-04-12

## README

Recoil types
=========================

To a second type parameter to selector of Recoil.


## Installation

To use Recoil Types with your app, install it as a dependency:

```bash
# If you use npm:
npm install recoil-types

# Or if you use Yarn:
yarn add recoil-types
```

## Example

Create a `userStore.ts` store file.

```ts
import { mapReducer, MapActions } from 'recruit';
import { atom, selector, DefaultValue } from 'recoil';

export interface User {
  id: number;
  name: string;
}

export type UserState = User | null;

export type UserActions = MapActions<UserState>;

export const initialState: UserState = null;

export const $userState = atom<UserState>({
  key: '$userState',
  default: initialState,
});

export const userState = selector<UserState, UserActions>({
  key: 'userState',
  get: ({get}) => get($userState),
  set: ({get, set, reset}, action) => {
    if (action instanceof DefaultValue) {
      return reset($userState);
    }

    return set($userState, mapReducer(get($userState), action));
  },
});
```

Create a `MyComponent.tsx` store file.

```tsx
import { useRecoilState } from 'recoil';
import { userState } from './userStore';

export default function MyComponents() {
  const [user, dispatch] = useRecoilState(userState);

  const set = () => {
    dispatch({
      type: 'set',
      payload: {id: 1, name: 'recoil'}
    });
  };
  const merge = () => {
    dispatch({
      type: 'merge',
      payload: {name: 'sanonz'}
    });
  };

  return (
    <div>
      <p>{JSON.stringify(user)}</p>
      <button onClick={set}>Set</button> | <button onClick={merge}>Merge</button>
    </div>
  );
}
```

## Issues

If you find a bug, please file an issue on [our issue tracker on GitHub](https://github.com/sanonz/react-recast/issues).

## License

[MIT](LICENSE.md)

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