()
- useEffect(() => {
- const handleResize = () => {
- setChartHeight(window.innerWidth < 800 ? mobileHeight : fullHeight)
- setChartWidth(containerRef.current?.clientWidth)
- }
- handleResize()
- window.addEventListener('resize', handleResize)
- return () => {
- window.removeEventListener('resize', handleResize)
- }
- }, [fullHeight, mobileHeight])
+ const { fullHeight, mobileHeight, contract, bets } = props
return (
-
- {chartWidth != null && chartHeight != null && (
+
+ {(width, height) => (
)}
-
+
)
}
@@ -114,7 +99,11 @@ const BinaryOverview = (props: { contract: BinaryContract; bets: Bet[] }) => {
-
+
ReactNode
+}) => {
+ const { children, fullHeight, mobileHeight } = props
+ const threshold = props.mobileThreshold ?? 800
+ const containerRef = useRef(null)
+ const [width, setWidth] = useState()
+ const [height, setHeight] = useState()
+ useEffect(() => {
+ if (containerRef.current) {
+ const handleResize = () => {
+ setHeight(window.innerWidth <= threshold ? mobileHeight : fullHeight)
+ setWidth(containerRef.current?.clientWidth)
+ }
+ handleResize()
+ const resizeObserver = new ResizeObserver(handleResize)
+ resizeObserver.observe(containerRef.current)
+ window.addEventListener('resize', handleResize)
+ return () => {
+ window.removeEventListener('resize', handleResize)
+ resizeObserver.disconnect()
+ }
+ }
+ }, [threshold, fullHeight, mobileHeight])
+ return (
+
+ {width != null && height != null && children(width, height)}
+
+ )
+}