Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
David Maskasky committed Oct 3, 2023
1 parent 8457666 commit abbcd70
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/mutableAtom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ atomWithProxy(proxyObject, { sync: true })

`mutableAtom` wraps a value in a self-aware Valtio proxy. You can make changes to it in the same way you would to a normal js-object.

### API Signature

```jsx
function mutableAtom<Value>(value: Value, options?: Options<Value>): Atom<{ value: Value}>
```

### Parameters

- **value** (required): the value to proxy.
- **options** (optional): allows customization with `proxyFn` for custom proxy functions.

### Example

Count value is stored under the `value` property.

```jsx
Expand All @@ -99,22 +86,23 @@ function IncrementButton() {
}
```

<CodeSandbox id="f84sk5" />
### Parameters

### Options
```js
mutableAtom(value, options?)
```
Options include `proxyFn` which can be `proxy` or a custom function.
**value** (required): the value to proxy.
```jsx
type ProxyFn<Value> = (obj: { value: Value }) => ({ value: Value })
**options.proxyFn** (optional): allows customization with `proxyFn` for custom proxy functions. Can be `proxy` (default) or a custom function.
type Options<Value> = {
proxyFn: ProxyFn<Value>
}
```
### Examples
<CodeSandbox id="f84sk5" />
### Caution on Mutating Proxies
Be careful not to mutate the proxy directly in the atom's read function or during render in React components. Doing so might trigger an infinite render loop.
Be careful to not mutate the proxy directly in the atom's read function or during render. Doing so could cause an infinite render loop.
```ts
const countProxyAtom = mutableAtom(0)
Expand Down

0 comments on commit abbcd70

Please sign in to comment.