diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-25 16:47:22 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-29 15:48:22 +0200 |
| commit | 8db3bead13441a5882d8689dfc6a9f09c82375d9 (patch) | |
| tree | e9d0cafa93904ffcbec3188c37961bcc16c6422d /legacy/use-element-registry.ts | |
| parent | 39ea298a9ccba3104c549c0ca079c231981811f5 (diff) | |
| download | opencut-8db3bead13441a5882d8689dfc6a9f09c82375d9.tar.gz | |
feat: masks, properties refactor, shaders, storage migrations, and more
Diffstat (limited to 'legacy/use-element-registry.ts')
| -rw-r--r-- | legacy/use-element-registry.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/legacy/use-element-registry.ts b/legacy/use-element-registry.ts new file mode 100644 index 00000000..85704318 --- /dev/null +++ b/legacy/use-element-registry.ts @@ -0,0 +1,31 @@ +import { useCallback, useRef } from "react"; + +export function useElementRegistry() { + const elementRefs = useRef<Map<string, HTMLElement>>(new Map()); + + const registerElement = useCallback( + (id: string, element: HTMLElement | null) => { + if (element) { + elementRefs.current.set(id, element); + return; + } + + elementRefs.current.delete(id); + }, + [], + ); + + const getElement = useCallback((id: string) => { + return elementRefs.current.get(id) ?? null; + }, []); + + const getElements = useCallback(() => { + return elementRefs.current; + }, []); + + return { + registerElement, + getElement, + getElements, + }; +} |
