From 968e8c6d70208782df3789ec1a057a6f01b0078b Mon Sep 17 00:00:00 2001 From: Seonglae Cho Date: Fri, 6 Jun 2025 15:42:15 +0100 Subject: [PATCH] feat(nreact): integrate Next.js Link for page navigation --- packages/nreact/src/context.tsx | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/nreact/src/context.tsx b/packages/nreact/src/context.tsx index 6f88650e..3632faa3 100644 --- a/packages/nreact/src/context.tsx +++ b/packages/nreact/src/context.tsx @@ -177,20 +177,25 @@ export const NotionContextProvider: React.FC = ({ }) => { for (const key of Object.keys(rest)) if (rest[key] === undefined) delete rest[key] - const wrappedThemeComponents = React.useMemo( - () => ({ - ...themeComponents - }), - [themeComponents] - ) + const wrappedThemeComponents = React.useMemo(() => { + const components = { ...themeComponents } + + if (components.nextImage) components.Image = wrapNextImage(components.nextImage) + + if (components.nextLink) { + const nextLink = wrapNextLink(components.nextLink) + components.nextLink = nextLink - if (wrappedThemeComponents.nextImage) wrappedThemeComponents.Image = wrapNextImage(themeComponents.nextImage) + if (!components.PageLink) components.PageLink = nextLink + if (!components.Link) components.Link = nextLink + } - if (wrappedThemeComponents.nextLink) wrappedThemeComponents.nextLink = wrapNextLink(themeComponents.nextLink) + // ensure the user can't override default components with falsy values + // since it would result in very difficult-to-debug react errors + for (const key of Object.keys(components)) if (!components[key]) delete components[key] - // ensure the user can't override default components with falsy values - // since it would result in very difficult-to-debug react errors - for (const key of Object.keys(wrappedThemeComponents)) if (!wrappedThemeComponents[key]) delete wrappedThemeComponents[key] + return components + }, [themeComponents]) const value = React.useMemo( () => ({