Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A ref that triggers a rerender
import { useState, useCallback } from 'react';
function useStateRef(initialValue) {
const [ref, setState] = useState(initialValue)
const callback = useCallback(
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