Skip to content

Commit

Permalink
docs: add useLayoutEffect warning mitigation (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
aretrace authored Sep 2, 2024
1 parent 7734e7b commit d5c06fc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/guides/migrating-to-v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ state.obj = deepClone(newObj)
// and do something later with `newObj`
```

### `useLayoutEffect` server warning

If you're using React 18 with SSR, add this conditional to prevent excessive warnings.

```js
import { snapshot, useSnapshot as useSnapshotOrig } from 'valtio'

const isSSR = typeof window === 'undefined'
export const useSnapshot = isSSR ? (p) => snapshot(p) : useSnapshotOrig

// render with `useSnapshot` as usual
```

## Links

- https://github.com/pmndrs/valtio/discussions/703
Expand Down

0 comments on commit d5c06fc

Please sign in to comment.