Last active
August 15, 2021 04:33
-
-
Save Stanley-Yao/fe59b183907e836791896cb5ce37ee10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState, useCallback } from "react"; | |
import { useResizeDetector } from "react-resize-detector"; | |
const AppGamma = () => { | |
const [widthA, setWidthA] = useState<number>(800); | |
const onResize = useCallback(() => { | |
// on resize logic | |
}, []); | |
const { width, ref } = useResizeDetector({ | |
onResize, | |
refreshMode: "debounce" | |
}); | |
useEffect(() => { | |
//do something with the width, remember to use debounce | |
console.log(width); | |
}, [width]); | |
return ( | |
<> | |
<h3> App Gamma </h3> | |
<div> | |
<button onClick={() => setWidthA(widthA + 100)}> ++ width </button> | |
<button onClick={() => setWidthA(widthA - 100)}> -- width </button> | |
</div> | |
<div className="container-gamma"> | |
<div className="child-app-A" style={{ width: widthA }}> | |
Widget A | |
</div> | |
<div className="child-app-B" ref={ref}> | |
Widget B width: <div>{width} px</div> | |
</div> | |
</div> | |
</> | |
); | |
}; | |
export default AppGamma; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment