Skip to content

Commit f078fe7

Browse files
committed
Total コンポーネントと total のメモ化の処理を削除
1 parent aeae980 commit f078fe7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/App.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback, useMemo, useState } from 'react';
1+
import { memo, useCallback, useState } from 'react';
22

33
const App = () => {
44
console.log('renders <App />');
@@ -63,23 +63,21 @@ const AddButton = ({ disabled, onClick }) => {
6363
);
6464
};
6565

66-
const Total = memo(({ cartItems }) => {
66+
const Total = ({ cartItems }) => {
6767
console.log('renders <Total />');
6868

69-
const total = useMemo(() => {
70-
return cartItems.reduce((acc, cur) => {
71-
const t = Date.now();
69+
const total = cartItems.reduce((acc, cur) => {
70+
const t = Date.now();
7271

73-
while (Date.now() - t < 100) {
74-
// 擬似的に100ミリ秒の遅延を発生させる
75-
}
72+
while (Date.now() - t < 100) {
73+
// 擬似的に100ミリ秒の遅延を発生させる
74+
}
7675

77-
return cur.length * 100 + acc;
78-
}, 0);
79-
}, [cartItems]);
76+
return cur.length * 100 + acc;
77+
}, 0);
8078

8179
return <p>合計: {total}</p>;
82-
});
80+
};
8381

8482
const ClearButton = memo(({ onClick }) => {
8583
console.log('renders <ClearButton />');

0 commit comments

Comments
 (0)