You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/components/MemoContent/EmbeddedContent/EmbeddedMemo.tsx

33 lines
886 B
TypeScript

import { useContext, useEffect } from "react";
import { useMemoStore } from "@/store/v1";
import MemoContent from "..";
import { RendererContext } from "../types";
interface Props {
memoId: number;
}
const EmbeddedMemo = ({ memoId }: Props) => {
const context = useContext(RendererContext);
const memoStore = useMemoStore();
const memo = memoStore.getMemoById(memoId);
const resourceName = `memos/${memoId}`;
useEffect(() => {
memoStore.getOrFetchMemoById(memoId);
}, [memoId]);
if (memoId === context.memoId || context.embeddedMemos.has(resourceName)) {
return <p>Nested Rendering Error: {`![[${resourceName}]]`}</p>;
}
context.embeddedMemos.add(resourceName);
return (
<div className="embedded-memo">
<MemoContent nodes={memo.nodes} memoId={memoId} embeddedMemos={context.embeddedMemos} />
</div>
);
};
export default EmbeddedMemo;