react-use-composed-ref
v1.1.1
Published
react use composed ref
Downloads
4
Maintainers
Readme
React useComposedRef
Hook
Usage
// AutoFocusInput.tsx
import React, { useRef, useEffect } from 'react';
import { useComposedRef } from 'react-use-composed-ref';
export const AutoFocusInput = React.forwardRef((props, ref) => {
const inputRef = useRef(null);
const composedRef = useComposedRef(inputRef, ref);
useEffect(() => {
inputRef.current.focus();
}, []);
return <input ref={composedRef} {...props} />;
});