Sobes.tech
Middle+

React.memo, özü komponentdən başqa hansı arqumentləri qəbul edir?

sobes.tech Süni İntellekt

AI-dan cavab

React.memo iki arqument qəbul edir:

  1. Komponent, yadda saxlanılacaq — adətən funksional komponent.
  2. Müqayisə funksiyası (istəyə bağlı) — iki props obyekti (prevProps və nextProps) qəbul edir və true qaytarırsa, propslar bərabər sayılır və yenidən renderə ehtiyac yoxdur, və ya false olsa, komponent yenilənməlidir.

Müqayisə funksiyası ilə istifadə nümunəsi:

const MyComponent = React.memo(function MyComponent(props) {
  // render
}, (prevProps, nextProps) => {
  // yalnız lazım olan sahələri müqayisə edirik
  return prevProps.value === nextProps.value;
});

Əgər müqayisə funksiyası verilməzsə, React.memo varsayılan olaraq propsların səthini müqayisə edir.