useRefHandler
Create a handler that can be used as ref,
Usage
useRefHandler
creates an handler that can be used as a ref
. It handles cleanup by returning a function like in a useEffect
.
import { useRefHandler } from "swash/utils/useRefHandler";
function Example({ onChange }) {
const ref = useRefHandler((element) => {
const handleClick = () => {
console.log("clicked");
};
element.addEventListener("click", handleClick);
return () => element.removeEventListener("click", handleClick);
});
return <button ref={ref} />;
}