import { useContext, useEffect } from "react"; import MemoResourceListView from "@/components/MemoResourceListView"; import useLoading from "@/hooks/useLoading"; import { useMemoStore } from "@/store/v1"; import MemoContent from ".."; import { RendererContext } from "../types"; import Error from "./Error"; interface Props { memoId: number; params: string; } const EmbeddedMemo = ({ memoId }: Props) => { const context = useContext(RendererContext); const loadingState = useLoading(); const memoStore = useMemoStore(); const memo = memoStore.getMemoById(memoId); const resourceName = `memos/${memoId}`; useEffect(() => { memoStore.getOrFetchMemoById(memoId).finally(() => loadingState.setFinish()); }, [memoId]); if (loadingState.isLoading) { return null; } if (!memo) { return ; } if (memoId === context.memoId || context.embeddedMemos.has(resourceName)) { return ; } // Add the memo to the set of embedded memos. This is used to prevent infinite loops when a memo embeds itself. context.embeddedMemos.add(resourceName); return (
); }; export default EmbeddedMemo;