useHandlerRef

import { useHandlerRef } from "reshaped";

useHandlerRef is meant to help in situations when you have to use an event handler inside a useEffect but this handler is your component property and you can't guarantee it was memoized. It uses refs to make sure you get the same ref instance to be used for the effect dependencies while updating the actual function as it changes in the product.

Here is a simple exapmple of how it can be used:

const Component = ({ onMount }) => {
  const onMountRef = useHandlerRef(onMount);

  React.useEffect(() => {
    onMountRef.current();
  }, [onMountRef]);
};
(
  handler: Function
)
Professionally crafted React & Figma components for building beautiful products or starting your own design system
Built with Reshaped in Amsterdam ❤️
Contact us·License agreement·FAQ·
© Reshaped 2025