Skip to content

Commit

Permalink
Filter out non block values from Blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
n6g7 committed Sep 17, 2020
1 parent de0c239 commit 6185476
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react/lib/Blocks.tsx
@@ -1,10 +1,10 @@
import React, { useMemo } from "react";
import { BlockValues, BlockType } from "@notion-cms/types";
import { BlockValues, BlockType, Person } from "@notion-cms/types";
import Block from "./Block";
import BlocksContext from "./BlocksContext";

interface Props {
blocks: BlockValues[];
blocks: (BlockValues | Person)[];
rootOnly: boolean;
}

Expand All @@ -17,7 +17,10 @@ const listMapping: Record<ListType, "ol" | "ul"> = {

const Blocks: React.FC<Props> = ({ blocks, rootOnly = true }) => {
const displayableBlocks = useMemo(
() => (rootOnly ? blocks.filter((b) => b.isRoot) : blocks),
() =>
blocks.filter(
(b) => "type" in b && (!rootOnly || b.isRoot)
) as BlockValues[],
[blocks, rootOnly]
);

Expand Down

0 comments on commit 6185476

Please sign in to comment.