Skip to content

Commit

Permalink
docs: changed markdown alerts to use emojis instead to work with both…
Browse files Browse the repository at this point in the history
… github the website (#993)

* changed github alerts to use emojis instead to work with both github and valtio.dev

* changed emoji codes to just use emojis

* ran prettier

* added more emojis

* ran prettier

* fixed span

* changed emoji to use text

* removed span

* removed span
  • Loading branch information
overthemike authored Nov 13, 2024
1 parent f3cbd01 commit e21edb3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
5 changes: 4 additions & 1 deletion docs/api/advanced/snapshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ This should be fine, because the expectation is that they execute very quickly (

In VanillaJS, `snapshot` is not necessary to access proxied object values, inside or outside of subscribe. However, it is useful, for example, to keep a serializable list of unproxied objects or check if objects have changed. It also resolves promises.

> [!TIP]
<br />

> 💡 Tip
>
> If you are using valtio outside of react, import from `valtio/vanilla`
>
> ```js
Expand Down
7 changes: 6 additions & 1 deletion docs/api/basic/useSnapshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ return <div>{profile.name}</div>

In dev mode, `useSnapshot` uses React's `useDebugValue` to output a list of fields that were accessed during rendering, i.e. which specific fields will trigger re-render when the tracking proxy changes.

> [!IMPORTANT]There are two disclaimers to using the debug value
<br />

> !! &nbsp; There are two disclaimers to
> using the debug value
>
> 1. Due to the way `useSnapshot` uses a proxy to recorded accesses _after_ `useSnapshot` has returned, the fields listed in `useDebugValue` are technically from the _previous_ render.
> 2. Object getter and class getter calls are not included in the `useDebugValue` output, but don't worry, they are actually correctly tracked internally and correctly trigger re-renders when changed.
<br />

## Codesandbox demo

https://codesandbox.io/s/ping-pong-with-valtio-wb25s?file=/src/App.js
14 changes: 11 additions & 3 deletions docs/guides/computed-properties.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ description: 'Use object getters and setters'

In Valtio you can use object & class getters and setters to create computed properties.

> [!NOTE]
<br />

> ℹ️ &nbsp; Note
> Getters in JavaScript are a more advanced feature of the language, so Valtio recommends using them with caution. That said, if you are a more advanced JavaScript programmer, they should work as you expect; see the "Note about using `this`" section below.
<br />

## Simple object getter

```js
Expand All @@ -36,8 +40,12 @@ When you call `state.doubled` on the `state` proxy, it is not cached, and will b

However, when you make a snapshot, calls to `snap.doubled` are effectively cached, because the value of an object getter is copied during the snapshot process.

> [!NOTE]
> In the current implementation a computed property should only reference **_sibling_** properties, otherwise you'll encounter weird bugs. For example:
<br />

> ℹ️ &nbsp; Note
> In the current implementation a computed property should only reference \*\*\_sibling\*\*\* properties, otherwise you'll encounter weird bugs. For example:
<br />

```js
const user = proxy({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ export { state, useSnapshot, subscribe }
}
```

> [!TIP] Using TypeScript? Here are some links for reference
<br />

> 💡 &nbsp; Using TypeScript? Here are some links for reference
>
> https://www.totaltypescript.com/tsconfig-cheat-sheet<br /> > https://github.com/tsconfig/bases<br /> > https://www.typescriptlang.org/tsconfig/
<br />

3. Add the **Module Resolver** plugin the plugins in your `babel.config.js`:

```js
Expand Down
7 changes: 6 additions & 1 deletion docs/how-tos/how-to-organize-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ Here's some recipes to show various patterns are possible.

## Action functions defined in module

> [!NOTE]
<br />

> ℹ️ &nbsp; Note
>
> This way is preferred as it is better for code splitting.
<br />

```js
import { proxy } from 'valtio'

Expand Down
7 changes: 6 additions & 1 deletion docs/how-tos/how-to-reset-state.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ const reset = () => {
}
```

> [!NOTE]
<br />

> ℹ️ &nbsp; Note
>
> Using `structuredClone()`
<br />

In 2022, there was a new global function added called `structuredClone` that is widely available in most modern browsers. You can use `structuredClone` in the same way as `deepClone` above, however `deepClone` is preferred as it will be aware of any `ref`s in your state.
3 changes: 0 additions & 3 deletions docs/how-tos/how-valtio-works.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ s7.obj === s8.obj // is true because obj is not changed

### `useSnapshot()` by examples

> [!NOTE]
> In the example below, we are bringing the state m
```jsx
import { proxy, useSnapshot } from 'valtio'

Expand Down
7 changes: 6 additions & 1 deletion docs/resources/libraries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ section: 'Resources'

Valtio provides bare necessities for proxy state management which is great for most projects; however, some users wish to extend the library's feature set. This can be done using 3rd-party libraries created by the community.

> [!WARNING]
<br />

> ⚠️ &nbsp; Warning
>
> Disclaimer: These libraries may have bugs, limited maintenance, or other limitations and are not officially recommended by pmndrs or the valtio maintainers. This list is to provide a good starting point for someone looking to extend valtio's feature set.
<br />

- [electron-valtio](https://github.com/water-a/electron-valtio) - Share state between the Electron main process and various renderer windows via valtio

- [eslint-plugin-valtio](https://github.com/pmndrs/eslint-plugin-valtio) - Eslint plugin for valtio
Expand Down

0 comments on commit e21edb3

Please sign in to comment.