useLiveRef

A React.Ref that keeps track of the passed value.

Usage

useLiveRef keeps track of the passed value. The main usage is to be able to avoid passing a prop as a dependency.

If you don't see the interest of this utility, you should read A complete Guide to useEffect.

import { useEffect } from "react";
import { useLiveRef } from "swash/utils/useLiveRef";

function Example({ onChange }) {
  const onChangeRef = useLiveRef(onChange);
  useEffect(() => {
    onChangeRef("...");
  }, []);
}