Skip to content

Commit f89f128

Browse files
authored
Merge pull request #16 from khaykingleb/refactoring
Refactoring
2 parents 3e39d42 + 9b0c5d7 commit f89f128

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

app/components/organisms/Carousel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const Carousel = ({ items }: { items: CarouselItem[] }) => {
1515
<div className="carousel carousel-vertical h-full w-full">
1616
{items.map((item, index) => (
1717
<Link
18-
to={`/notion/${item.notionPageId}`}
18+
to={`/blog/${item.notionPageId}`}
1919
id={`item${index}`}
2020
key={item.id}
2121
className="carousel-item block w-full cursor-pointer transition-all duration-300 hover:bg-gray-100"

app/routes/notion.$pageid.tsx app/routes/blog.$pageid.tsx

+28-35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defer, LoaderFunction, LoaderFunctionArgs } from "@remix-run/node";
22
import { Await, useLoaderData } from "@remix-run/react";
33
import { NotionAPI } from "notion-client";
4-
import React, { lazy, Suspense, useEffect, useState } from "react";
4+
import React, { lazy, Suspense } from "react";
55
import { ClientOnly } from "remix-utils/client-only";
66
import {
77
CodeBlock,
@@ -54,40 +54,33 @@ const Collection = lazy(() =>
5454
})),
5555
);
5656

57-
function NotionPage({ recordMap }: { recordMap: ExtendedRecordMap }) {
58-
const [isMounted, setIsMounted] = useState(false);
59-
60-
// Prevent hydration errors
61-
useEffect(() => {
62-
setIsMounted(true);
63-
}, []);
64-
if (!isMounted) {
65-
return null;
66-
}
67-
68-
return (
69-
<NotionRenderer
70-
recordMap={recordMap}
71-
fullPage={true}
72-
darkMode={false}
73-
disableHeader={true}
74-
components={{
75-
Pdf,
76-
Collection,
77-
Equation: (props: React.ComponentProps<typeof Equation>) => (
78-
<ClientOnly fallback={<div>Loading equation...</div>}>
79-
{() => <Equation {...props} />}
80-
</ClientOnly>
81-
),
82-
Code: (props: React.ComponentProps<typeof Code>) => (
83-
<ClientOnly fallback={<div>Loading code...</div>}>
84-
{() => <Code {...props} />}
85-
</ClientOnly>
86-
),
87-
}}
88-
/>
89-
);
90-
}
57+
const NotionPage = React.memo(
58+
({ recordMap }: { recordMap: ExtendedRecordMap }) => {
59+
return (
60+
<NotionRenderer
61+
recordMap={recordMap}
62+
fullPage={true}
63+
darkMode={false}
64+
disableHeader={true}
65+
components={{
66+
Pdf,
67+
Collection,
68+
Equation: (props: React.ComponentProps<typeof Equation>) => (
69+
<ClientOnly fallback={<div>Loading equation...</div>}>
70+
{() => <Equation {...props} />}
71+
</ClientOnly>
72+
),
73+
Code: (props: React.ComponentProps<typeof Code>) => (
74+
<ClientOnly fallback={<div>Loading code...</div>}>
75+
{() => <Code {...props} />}
76+
</ClientOnly>
77+
),
78+
}}
79+
/>
80+
);
81+
},
82+
);
83+
NotionPage.displayName = "NotionPage";
9184

9285
export const loader: LoaderFunction = async ({
9386
params,
File renamed without changes.

0 commit comments

Comments
 (0)