import { useCallback, useState } from "react";
const Index = () => {
const [name, setName] = useState<string>("");
// 引数valの値をconsole.logで出力
// 依存配列は[]
const handleClick = useCallback((val: string) => {
console.log("callback " + val);
}, []);
return (
<div className="w-screen h-screen bg-red-50">
<div className="w-full h-full flex justify-center items-center">
<div className="w-1/2 h-1/2 bg-slate-200">
<div className="w-full h-full flex justify-center items-center">
<button
onClick={() => handleClick(name)}
className="p-2 rounded-sm bg-indigo-400 text-white shadow-md"
>
Click me
</button>
<input
type="text"
value={name}
onChange={(e) => setName(e.currentTarget.value)}
/>
</div>
</div>
</div>
</div>
);
};
export default Index;