Skip to content

Commit

Permalink
useCallbackとuseEffectの第二引数について
Browse files Browse the repository at this point in the history
  • Loading branch information
koma0504 committed Jun 17, 2021
1 parent 2b056de commit c1e2c9b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import { useState } from "react";

export default function Home({ blog }) {
const [count, setCount] = useState(1);
const hendleClick = (e) => {
setCount((count) => count + 1);
};
console.log("count", count);
// useEffect(() => {
// console.log("マウント時");
// return () => {
// console.log("アンマウント時");
// };
// }, []);
const hendleClick = useCallback(() => {
console.log(count);
if (count < 10) {
setCount((count) => count + 1);
}
}, [count]);

useEffect(() => {
console.log("マウント時");
return () => {
console.log("アンマウント時");
};
}, [count]);
return (
<div className="body">
<Header title="RATIO OBSERVER" layout="swiper" />
Expand Down

1 comment on commit c1e2c9b

@vercel
Copy link

@vercel vercel bot commented on c1e2c9b Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.