-
Notifications
You must be signed in to change notification settings - Fork 49.2k
Open
Labels
React 18Bug reports, questions, and general feedback about React 18Bug reports, questions, and general feedback about React 18Type: Discussion
Description
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>
}
MaxmaxmaximusAWS, ady642 and MauroTaliente
Metadata
Metadata
Assignees
Labels
React 18Bug reports, questions, and general feedback about React 18Bug reports, questions, and general feedback about React 18Type: Discussion