import React, { useCallback } from 'react'; import { useNode } from './Node.hooks'; import { withErrorBoundary } from 'react-error-boundary'; import { ErrorBoundaryFallbackComponent } from '../_shared/ErrorBoundaryFallbackComponent'; import TextBlock from '../TextBlock'; import { NodeContext } from '../_shared/SubscribeNode.hooks'; import { BlockType } from '$app/interfaces/document'; import HeadingBlock from '$app/components/document/HeadingBlock'; function NodeComponent({ id, ...props }: { id: string } & React.HTMLAttributes) { const { node, childIds, isSelected, ref } = useNode(id); const renderBlock = useCallback(() => { switch (node.type) { case BlockType.TextBlock: { return ; } case BlockType.HeadingBlock: { return ; } default: return null; } }, [node, childIds]); if (!node) return null; return (
{renderBlock()}
{isSelected ? (
) : null}
); } const NodeWithErrorBoundary = withErrorBoundary(NodeComponent, { FallbackComponent: ErrorBoundaryFallbackComponent, }); export default React.memo(NodeWithErrorBoundary);