Skip to content

Commit

Permalink
added diff below code examples in migration-to-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
overthemike committed Aug 31, 2024
1 parent 04f5064 commit e60ac13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/api/utils/devtools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ The screenshot below shows how to use Redux DevTools to manipulate state. First

#### Use it with vanilla JS

```jsx
Valtio is not tied to React, you can use it in vanillaJS.

```jsx
import { proxy, subscribe, snapshot } from 'valtio/vanilla'

const state = proxy({ count: 0, text: 'llo' })
Expand Down
19 changes: 18 additions & 1 deletion docs/guides/migrating-to-v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,37 @@ Other notable changes to keep things updated and fresh include:
### Resolving promises

```js
// v1
import { proxy, useSnapshot } from 'valtio'

const state = proxy({ data: fetch(...).then((res) => res.json()) })

const Component = () => {
const snap = useSnapshot(state)
return <>{JSON.stringify(snap.data)}</>
}
```

```js
// v2
import { use } from 'react'
import { proxy, useSnapshot } from 'valtio'

const state = proxy({ data: fetch(...).then((res) => res.json()) })

const Component = () => {
const snap = useSnapshot(state)
return <>{JSON.stringify(use(snap.data))}</>
// If `data` is not an object, you can directly embed it in JSX.
// return <>{snap.data}</>
}
```

```diff
- return <>{JSON.stringify(snap.data)}</> // v1
+ return <>{JSON.stringify(use(snap.data))}</> // v2
+ // If `data` is not an object, you can embed it directly in JSX.
+ // return <>{snap.data}</>
}
```

### Impure `proxy(obj)`
Expand Down

0 comments on commit e60ac13

Please sign in to comment.