import React, { useCallback } from 'react'; import { useNode } from './Node.hooks'; import { withErrorBoundary } from 'react-error-boundary'; import { ErrorBoundaryFallbackComponent } from '../_shared/ErrorBoundaryFallbackComponent'; import { Node } from '@/appflowy_app/stores/reducers/document/slice'; import TextBlock from '../TextBlock'; import { TextDelta } from '@/appflowy_app/interfaces/document'; function NodeComponent({ id, ...props }: { id: string } & React.HTMLAttributes) { const { node, childIds, delta, isSelected, ref } = useNode(id); console.log('=====', id); const renderBlock = useCallback((_props: { node: Node; childIds?: string[]; delta?: TextDelta[] }) => { switch (_props.node.type) { case 'text': if (!_props.delta) return null; return ; default: break; } }, []); if (!node) return null; return (
{renderBlock({ node, childIds, delta, })}
{isSelected ?
: null}
); } const NodeWithErrorBoundary = withErrorBoundary(NodeComponent, { FallbackComponent: ErrorBoundaryFallbackComponent, }); export default React.memo(NodeWithErrorBoundary);