Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A ref that triggers a rerender https://codesandbox.io/s/3q2nvl3vop
import { useState, useCallback } from 'react';
function useStateRef(initialValue) {
const [ref, setState] = useState(initialValue)
const callback = useCallback(
ref => {
setState(ref)
},
[ref, setState]
)
callback.current = ref
return callback
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment