import { LiveMap , LiveObject } from "@liveblocks/client" ; import { useRoom } from "@liveblocks/react" ; import { useState , useEffect } from "react" ; import { Layer , XYWH } from "./types" ; import { boundingBox } from "./utils" ; export default function useSelectionBounds ( layers , selection ) { const [ bounds , setBounds ] = useState ( boundingBox ( layers , selection ) ) ; const room = useRoom ( ) ; useEffect ( ( ) => { function onChange ( ) { setBounds ( boundingBox ( layers , selection ) ) ; } onChange ( ) ; return room . subscribe ( layers , onChange , { isDeep : true } ) ; } , [ room , layers , selection ] ) ; return bounds ; }