Skip to content

Commit

Permalink
fix(utils): useProxy to avoid re-renders when no props are touched (#809
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dai-shi authored Nov 28, 2023
1 parent d1e462e commit 01672d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/react/utils/useProxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useLayoutEffect } from 'react'
import { useSnapshot } from '../../react.ts'

const DUMMY_SYMBOL = Symbol()

/**
* useProxy
*
Expand Down Expand Up @@ -28,8 +30,10 @@ export function useProxy<T extends object>(
): T {
const snapshot = useSnapshot(proxy, options) as T

let isRendering = true
// touch dummy prop so that it doesn't trigger re-renders when no props are touched.
;(snapshot as any)[DUMMY_SYMBOL]

let isRendering = true
useLayoutEffect(() => {
// This is an intentional hack
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

1 comment on commit 01672d9

@vercel
Copy link

@vercel vercel bot commented on 01672d9 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

valtio – ./

valtio-pmndrs.vercel.app
valtio-git-main-pmndrs.vercel.app
valtio.vercel.app
valtio.pmnd.rs

Please sign in to comment.