Skip to content

Instantly share code, notes, and snippets.

@alx8437
Created November 24, 2021 18:20
Show Gist options
  • Select an option

  • Save alx8437/61ed49aeb474b4b5695505601618f063 to your computer and use it in GitHub Desktop.

Select an option

Save alx8437/61ed49aeb474b4b5695505601618f063 to your computer and use it in GitHub Desktop.

Revisions

  1. alx8437 created this gist Nov 24, 2021.
    9 changes: 9 additions & 0 deletions Set heigth, with parent block by useCallback
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    const [containerHeight, setContainerHeight] = useState<number>(0);

    const containerHeightRef = useCallback((node) => {
    if (node !== null) {
    setContainerHeight(node.getBoundingClientRect().height);
    }
    }, []);

    <div ref={containerHeightRef}></div>