Closed cball closed 3 years ago
Oops. @transitive-bullshit it looks like you've already started a version of this in #13. I'm not sure there's a ton of a benefit in a provider/consumer approach vs what I've suggested here, but I could be missing a use case you have.
Thanks for this PR! We plan to move this forward in the coming week, when we have some time to spend on react-notion.
Are there any downsides compared to the Context approach? Would love to hear @transitive-bullshit thoughts on this.
I think we can merge this now. @tobiaslins
It's now possible to overwrite decorator components as well. So full flexibility with this change 🙂
Here is an example that demos both decorator components as well as blocks. It adds target="_blank"
to all text links, as well as wrapping page links with a Next.js link.
<NotionRenderer
blockMap={blockMap}
fullPage
hideHeader
customDecoratorComponents={{
a: ({ decoratorValue, children }) => (
<a href={decoratorValue} target="_blank" rel="noopener noreferrer">
{children}
</a>
)
}}
customBlockComponents={{
page: ({ blockValue, renderComponent }) => (
<Link href={`/${blockValue.id}`}>{renderComponent()}</Link>
)
}}
/>
I am in the process of exporting our blog from Medium and wanted to make sure elements of our posts can be rendered by this library.
In doing so, we needed to render a tweet, but by adding it to this library it would include extra dependencies that aren't always needed. I'd like to propose adding a
customComponents
prop that takes mapping of block types and components. The components are called with theblockValue
prop.This way,
react-notion
can provide a base set of components, but everything can be overridden.Let me know what you think!
Here's what the code looks like right now in the consuming app (using Next.js):
And the component: