Skip to content

Commit d8980c7

Browse files
authored
merge: pull request #228 from texonom/sd8ny3-codex/add-next.js-link-support-for-collection
feat(nreact): use Next.js Link for page links
2 parents 2142846 + 968e8c6 commit d8980c7

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

packages/nreact/src/context.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,25 @@ export const NotionContextProvider: React.FC<PartialNotionContext> = ({
177177
}) => {
178178
for (const key of Object.keys(rest)) if (rest[key] === undefined) delete rest[key]
179179

180-
const wrappedThemeComponents = React.useMemo(
181-
() => ({
182-
...themeComponents
183-
}),
184-
[themeComponents]
185-
)
180+
const wrappedThemeComponents = React.useMemo(() => {
181+
const components = { ...themeComponents }
182+
183+
if (components.nextImage) components.Image = wrapNextImage(components.nextImage)
184+
185+
if (components.nextLink) {
186+
const nextLink = wrapNextLink(components.nextLink)
187+
components.nextLink = nextLink
186188

187-
if (wrappedThemeComponents.nextImage) wrappedThemeComponents.Image = wrapNextImage(themeComponents.nextImage)
189+
if (!components.PageLink) components.PageLink = nextLink
190+
if (!components.Link) components.Link = nextLink
191+
}
188192

189-
if (wrappedThemeComponents.nextLink) wrappedThemeComponents.nextLink = wrapNextLink(themeComponents.nextLink)
193+
// ensure the user can't override default components with falsy values
194+
// since it would result in very difficult-to-debug react errors
195+
for (const key of Object.keys(components)) if (!components[key]) delete components[key]
190196

191-
// ensure the user can't override default components with falsy values
192-
// since it would result in very difficult-to-debug react errors
193-
for (const key of Object.keys(wrappedThemeComponents)) if (!wrappedThemeComponents[key]) delete wrappedThemeComponents[key]
197+
return components
198+
}, [themeComponents])
194199

195200
const value = React.useMemo(
196201
() => ({

0 commit comments

Comments
 (0)