Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

callback ref typescript

const useCustom = (): [
  RefObject<HTMLDivElement>,
  (node: HTMLDivElement) => void
] => {
  const ref = useRef<HTMLDivElement | null>(null);
  const setRef = useCallback((node: unknown) => {
    ref.current = node;
  }, []);

  return [ref, setRef];
};
 
PREVIOUS NEXT
Tagged: #callback #ref #typescript
ADD COMMENT
Topic
Name
3+2 =