⚡ useCallback Nedir?


⚡ Temel Kullanım

import { useState, useCallback } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  // Fonksiyon sadece count değiştiğinde yeniden oluşturulur
  const increment = useCallback(() => {
    setCount(c => c + 1);
  }, []); // bağımlılık dizisi boşsa, ilk renderdan sonra değişmez

  return (
    <div>
      <p>Count: {count}</p>
      <Button onClick={increment}>Arttır</Button>
    </div>
  );
}

const Button = React.memo(({ onClick, children }) => {
  console.log("Button render oldu");
  return <button onClick={onClick}>{children}</button>;
});


⚡ Notlar