Skip to content

Commit

Permalink
docs: sync
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Jun 27, 2024
1 parent e735b4e commit 3c1585c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/src/content/docs/package/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Developer tools for states and actions inspecting
npm install @reatom/devtools
```

**Note** that this package is published with ESM bundle only.

## Usage

You typical setup would look like that.
Expand All @@ -32,3 +34,12 @@ if (import.meta.env.DEV) {

// ...
```

`connectDevtools` has an optional second argument where you can specify how to process an atoms names.

```ts
type Options = {
separator?: string | RegExp | ((name: string) => Array<string>) // default is /\.|#/
privatePrefix?: string // default is '_'
}
```
6 changes: 6 additions & 0 deletions docs/src/content/docs/package/npm-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export const SomeList = reatomComponent(

Do not forget to put the component name to the second argument, it will increase your feature debug experience a lot!

#### Unmount

An important feature of `reatomComponent` is automatic resource management with default for Reatom AbortController in the cause context. You may be familiar with this concept from [@reatom/effects](/package/effects/). The `ctx` in reatomComponent props includes the AbortController which is followed by all derived actions. For example, it means if you will update an atom from the component and it will cause [reatomResource](/package/async/#reatomresource) refetch and the component will unmaunt before the fetch end - the fetch will throw an abort error.

This increases the stability of your application as it reduces the amount of possible race conditions. But be aware that sometimes you may want to create a request that you don't want to abort even if the unmount occurs. For example, it might be an analytic event, in which case you should use [spawn](/package/effects/#spawn).

### useAtom

`useAtom` is your main hook, when you need to describe reusable logic in hight order hook. It accepts an atom to read it value and subscribes to the changes, or a primitive value to create a new mutable atom and subscribe to it. It alike `useState`, but with many additional features. It returns a tuple of `[state, setState, theAtom, ctx]`. `theAtom` is a reference to the passed or created atom.
Expand Down

0 comments on commit 3c1585c

Please sign in to comment.