Skip to content

Commit

Permalink
docs(readme): add makeCreator() doc
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Jul 31, 2023
1 parent df30685 commit ac87007
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Use `create()` for more advanced features by [setting `options`](#createstate-fn
- [`isDraft()`](#isDraft)
- [`isDraftable()`](#isDraftable)
- [`rawReturn()`](#rawReturn)
- [`makeCreator()`](#makeCreator)

### `create()`

Expand All @@ -206,7 +207,9 @@ const state = create(baseState, (draft) => {

In this basic example, the changes to the draft are 'mutative' within the draft callback, and `create()` is finally executed with a new immutable state.

#### `create(state, fn, options)` - Then options is optional.
#### `create(state, fn, options)`

> Then options is optional.
- strict - `boolean`, the default is false.

Expand Down Expand Up @@ -421,6 +424,26 @@ expect(state).toEqual({ a: 2, b: { c: 1 } });
expect(isDraft(state.b)).toBeFalsy();
```

### `makeCreator()`

`makeCreator()` only takes [options](#createstate-fn-options) as the first argument, resulting in a custom `create()` function.

```ts
const baseState = {
foo: {
bar: 'str',
},
};

const create = makeCreator({
enablePatches: true,
});

const [state, patches, inversePatches] = create(baseState, (draft) => {
draft.foo.bar = 'new str';
});
```

[View more API docs](./docs/README.md).

## Using TypeScript
Expand Down

0 comments on commit ac87007

Please sign in to comment.