Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

useref typescript

import { useRef, useLayoutEffect } from "react";

//HTMLInputElement || define the type of element
const element = useRef<HTMLInputElement>(null);

useLayoutEffect(() => {
//object can be null
  if (element.current !== null) {
    element.current.focus();
  }
});
Source by www.carlrippon.com #
 
PREVIOUS NEXT
Tagged: #useref #typescript
ADD COMMENT
Topic
Name
3+7 =