Skip to content

Commit

Permalink
🐛 와우! 마지막 테스트 통과 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyMan0 committed Jan 2, 2025
1 parent e0d30e4 commit 9a011e3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/components/common/header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { memo } from "../../@lib";
import { useAuthContext } from "../../providers/auth-provider";
import {
useThemeContext,
useUpdateThemeContext,
} from "../../providers/theme-provider";
import { renderLog } from "../../utils";

const Header = () => {
const Header: React.FC = memo(() => {
renderLog("Header rendered");
const { user, login, logout } = useAuthContext();
const theme = useThemeContext();
Expand Down Expand Up @@ -52,6 +53,6 @@ const Header = () => {
</div>
</header>
);
};
});

export default Header;
9 changes: 4 additions & 5 deletions src/components/item-list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from "react";
import { memo } from "../@lib";
import { useThemeContext } from "../providers/theme-provider";
import { renderLog } from "../utils";

Expand All @@ -9,12 +10,10 @@ interface Item {
price: number;
}

interface ItemListProps {
export const ItemList: React.FC<{
items: Item[];
onAddItemsClick: () => void;
}

export const ItemList = ({ items, onAddItemsClick }: ItemListProps) => {
}> = memo(({ items, onAddItemsClick }) => {
renderLog("ItemList rendered");
const [filter, setFilter] = useState("");
const theme = useThemeContext();
Expand Down Expand Up @@ -67,4 +66,4 @@ export const ItemList = ({ items, onAddItemsClick }: ItemListProps) => {
</ul>
</div>
);
};
});
10 changes: 6 additions & 4 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";
import { useCallback, useState } from "react";

import { useMemo } from "../@lib";
import { useThemeContext } from "../providers/theme-provider";
import { generateItems } from "../utils";
import Header from "./common/header";
Expand All @@ -9,13 +10,14 @@ import NotificationSystem from "./notification-system";

const CommonLayout = () => {
const theme = useThemeContext();
const [items, setItems] = useState(generateItems(1000));
const addItems = () => {
const memoizedItems = useMemo(() => generateItems(1000), []);
const [items, setItems] = useState(memoizedItems);
const addItems = useCallback(() => {
setItems((prevItems) => [
...prevItems,
...generateItems(1000, prevItems.length),
]);
};
}, []);

return (
<div
Expand Down
2 changes: 1 addition & 1 deletion src/components/notification-system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNotificationContext } from "../providers/notification-provider";

import { renderLog } from "../utils";

const NotificationSystem = memo(() => {
const NotificationSystem: React.FC = memo(() => {
renderLog("NotificationSystem rendered");
const { notifications, removeNotification } = useNotificationContext();

Expand Down

0 comments on commit 9a011e3

Please sign in to comment.