import {reactive, RenderNode} from "@peryl/react-compose"; import {Reference} from "../components/Reference"; /** * 自动管理自定义内容的时候的reference渲染方式 * @author 韦胜健 * @date 2022/8/16 14:24 */ export function useRenderReference() { const state = reactive({ getReference: null as null | (() => HTMLElement) }); const renderReference = ( { slotRender, slotExist, defaultRender }: { slotExist: () => boolean, slotRender: () => RenderNode, defaultRender: () => RenderNode }) => { return slotExist() ? {slotRender()} : defaultRender(); }; const getReference = () => state.getReference?.(); const onElementDetected = (el: HTMLElement | null) => {state.getReference = !el ? null : (() => el);}; return { getReference, renderReference }; }