streamich / react-use

React Hooks — 👍
http://streamich.github.io/react-use
The Unlicense
41.93k stars 3.16k forks source link

Add useLatestRef() and useLayoutLatestRef() #2509

Open pastelmind opened 1 year ago

pastelmind commented 1 year ago

Description

This PR adds two hooks useLatestRef() and useLayoutLatestRef() as described in https://github.com/streamich/react-use/issues/2328#issuecomment-1633958158. They are similar to useLatest(), but avoid updating the ref directly during render, which is deemed unsafe by the React team..

This PR also marks useLatest() as @deprecated and recommend useLatestRef() as an alternative.

Type of change

Checklist

nmoinvaz commented 1 year ago

Nice PR!

nathggns commented 10 months ago

Really hope this is merged. useLatest is not safe.

hengkx commented 7 months ago

Is there any progress?