Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-808
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Nov 5, 2023
2 parents b6964bd + a39759a commit e4c8324
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 12 additions & 3 deletions docs/guides/component-state.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ const MyCounter = () => {
}
```

If you are not happy with useRef usage, consider [use-constant](https://www.npmjs.com/package/use-constant) instead.
You may also create custom hooks wrapping useContext and optionally useSnapshot.

## Codesandbox example

https://codesandbox.io/s/valtio-component-ye5tbg?file=/src/App.tsx

## Alternatives

If you are not happy with useRef usage, consider:

- [use-constant](https://www.npmjs.com/package/use-constant)
- [bunshi](https://www.bunshi.org/recipes/valtio/)
- You may also create custom hooks wrapping useContext and optionally useSnapshot.

### Bunshi example

https://codesandbox.io/s/77r53c?file=/molecules.ts
13 changes: 11 additions & 2 deletions docs/how-tos/how-to-use-with-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@ const MyCounter = () => {
}
```

- If you are not happy with `useRef` usage, consider [use-constant](https://www.npmjs.com/package/use-constant) instead.
- You can create custom hooks to `useContext` and optionally `useSnapshot`.
## Alternatives

If you are not happy with `useRef` usage, consider:

- [use-constant](https://www.npmjs.com/package/use-constant)
- [bunshi](https://www.bunshi.org/recipes/valtio/)
- You can create custom hooks to `useContext` and optionally `useSnapshot`

### Bunshi example

https://codesandbox.io/s/77r53c?file=/molecules.ts

0 comments on commit e4c8324

Please sign in to comment.