diff --git a/src/react-portable-text.tsx b/src/react-portable-text.tsx
index a6f9750..7c5b9e7 100644
--- a/src/react-portable-text.tsx
+++ b/src/react-portable-text.tsx
@@ -88,7 +88,11 @@ const getNodeRenderer = (
return renderSpan(node, index, key)
}
- if (node._type === 'block' && isPortableTextBlock(node)) {
+ if (hasCustomComponentForNode(node)) {
+ return renderCustomBlock(node, index, key, isInline)
+ }
+
+ if (isPortableTextBlock(node)) {
return renderBlock(node, index, key, isInline)
}
@@ -96,7 +100,11 @@ const getNodeRenderer = (
return renderText(node, key)
}
- return renderCustomBlock(node, index, key, isInline)
+ return renderUnknownType(node, index, key, isInline)
+ }
+
+ function hasCustomComponentForNode(node: TypedObject): boolean {
+ return node._type in components.types
}
/* eslint-disable react/jsx-no-bind */
@@ -209,9 +217,7 @@ const getNodeRenderer = (
return node.text
}
- function renderCustomBlock(node: TypedObject, index: number, key: string, isInline: boolean) {
- const Node = components.types[node._type]
-
+ function renderUnknownType(node: TypedObject, index: number, key: string, isInline: boolean) {
const nodeOptions = {
value: node,
isInline,
@@ -219,15 +225,23 @@ const getNodeRenderer = (
renderNode,
}
- if (Node) {
- return
- }
-
handleMissingComponent(unknownTypeWarning(node._type), {nodeType: 'block', type: node._type})
const UnknownType = components.unknownType
return
}
+
+ function renderCustomBlock(node: TypedObject, index: number, key: string, isInline: boolean) {
+ const nodeOptions = {
+ value: node,
+ isInline,
+ index,
+ renderNode,
+ }
+
+ const Node = components.types[node._type]
+ return Node ? : null
+ }
/* eslint-enable react/jsx-no-bind */
return renderNode
diff --git a/test/fixtures/index.ts b/test/fixtures/index.ts
index dad88d5..cbc5b90 100644
--- a/test/fixtures/index.ts
+++ b/test/fixtures/index.ts
@@ -24,11 +24,11 @@ import inlineBlockWithText from './026-inline-block-with-text'
import styledListItems from './027-styled-list-items'
import customListItemType from './028-custom-list-item-type'
import customBlockType from './050-custom-block-type'
-import customBlockTypeWithChildren from './062-custom-block-type-with-children'
import customMarks from './052-custom-marks'
import overrideDefaultMarks from './053-override-default-marks'
import listIssue from './060-list-issue'
import missingMarkComponent from './061-missing-mark-component'
+import customBlockTypeWithChildren from './062-custom-block-type-with-children'
export {
emptyBlock,