react-bits icon indicating copy to clipboard operation
react-bits copied to clipboard

[BUG]: text-animations/scroll-velocity on TS + Tailwind on ESLint

Open Xusk947 opened this issue 8 months ago • 0 comments

Describe the issue

ESLint error

Explain what this problem is and help me fix it: Argument of type 'RefObject<HTMLSpanElement | null>' is not assignable to parameter of type 'RefObject<HTMLElement>'.
  Type 'HTMLSpanElement | null' is not assignable to type 'HTMLElement'.
    Type 'null' is not assignable to type 'HTMLElement'. 

The error is because strict types

The fix is to change the useElementWidth

After that everything should be fine

Reproduction Link

No response

Steps to reproduce

  1. Install ESLint with strict mode
  2. Run npm run lint
  3. And there will be an error

to fix that we ened to change useElementWidth

to

function useElementWidth<T extends HTMLElement>(ref: React.RefObject<T | null>): number {
  const [width, setWidth] = useState(0);

  useLayoutEffect(() => {
    function updateWidth() {
      if (ref.current) {
        setWidth(ref.current.offsetWidth);
      }
    }
    updateWidth();
    window.addEventListener("resize", updateWidth);
    return () => window.removeEventListener("resize", updateWidth);
  }, [ref]);

  return width;
}

Validations

  • [x] I have checked other issues to see if my issue was already reported or addressed

Xusk947 avatar Jun 07 '25 05:06 Xusk947