Let's add this hook as part of the core. Since this is a common need, many people often ask the question "Why does useEffect not sense ref.current changes?"
// approximate implementation
const useReactiveRef = (defaultValue) => {
const [current, ref] = useState(defaultValue)
ref.current = current
return ref
}
Usage example:
const Component = () => {
const ref = React.useReactiveRef()
useEffect(() => {
// ref.current now is reactive
console.log(ref.current)
}, [ref.current])
return <div ref={ref}></div>
}
Let's add this hook as part of the core. Since this is a common need, many people often ask the question "Why does useEffect not sense ref.current changes?"
Usage example: