Skip to content

Commit

Permalink
chore: update docs/immer with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Oct 17, 2020
1 parent 244f71b commit a1e0c4e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion docs/immer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
This doc describes `jotai/immer` bundle.

## Install

You have to install `immer` to access this bundle and its functions.

```
npm install immer
# or
Expand Down Expand Up @@ -31,6 +34,12 @@ const Controls = () => {
}
```

### Examples

Check examples with atomWithImmer:

- https://codesandbox.io/s/jotai-immer-example-8zrqs

## withImmer

`withImmer` takes an atom and returns a derived atom, same as `atomWithImmer` it has a different `writeFunction`.
Expand All @@ -56,8 +65,11 @@ const Controls = () => {
```

## useImmerAtom

This hook takes an atom and replaces the atom's `writeFunction` with the new immer-like `writeFunction` like the previous helpers.

```jsx

import { useAtom } from 'jotai'
import { useImmerAtom } from 'jotai/immer'

Expand All @@ -78,5 +90,7 @@ const Controls = () => {
```

It would be better if you don't use `withImmer` and `atomWithImmer` with `useImmerAtom` because they provide the immer-like `writeFunction` and we don't need to create a new one.

## Codesandbox
A good example of this bundle in [codesandbox](https://codesandbox.io/s/immer-jotai-doc-ms9pv?file=/src/App.tsx).

A good example of this bundle in [codesandbox](https://codesandbox.io/s/immer-jotai-doc-ms9pv?file=/src/App.tsx).

0 comments on commit a1e0c4e

Please sign in to comment.