Skip to content

Commit

Permalink
refactor: added useSize hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zyishai committed Dec 12, 2024
1 parent 75b899e commit 3f1dae6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/hooks/use-size.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
import { useEffect, useState } from "react";
import { DOMElement, measureElement } from "ink";

export interface SizeType {
width: number;
height: number;
}

export const useSize = (ref?: DOMElement | null): SizeType => {
const [size, setSize] = useState<SizeType>({ width: 0, height: 0 });

useEffect(() => {
if (ref) {
setSize(measureElement(ref));
}
}, [ref]);

return size;
};

0 comments on commit 3f1dae6

Please sign in to comment.