import { IElementState } from "../types"; export const useRefHook = (state: IElementState) => { const currentRefNumber = state.tickState.currentRefNumber; state.tickState.currentRefNumber++; if (state.isFirstTick) { const ref = { current: undefined, }; state.refs.push(ref); return ref; } const existingRef = state.refs[currentRefNumber]; if (!existingRef) { throw new Error("Unexpected useRefHook, not found ref with number " + currentRefNumber); } return existingRef; };