reactuse icon indicating copy to clipboard operation
reactuse copied to clipboard

useLatest疑问

Open rubbishmaker opened this issue 8 months ago • 2 comments

useLatest为什么使用effect监听一层,为什么不直接ref.current = value。

rubbishmaker avatar Apr 04 '25 06:04 rubbishmaker

直接在渲染中赋值ref是反模式,在react18的并发渲染特性开启的时候会有问题。

childrentime avatar Apr 07 '25 02:04 childrentime

https://react.dev/reference/react/useRef#referencing-a-value-with-a-ref

childrentime avatar Apr 07 '25 03:04 childrentime

https://github.com/childrentime/reactuse/issues/115

FleetAdmiralJakob avatar May 23 '25 11:05 FleetAdmiralJakob