import React, { useEffect } from 'react';
function EffectComponent({ userId }) {
useEffect(() => {
const fetchUserData = async () => {
const response = await fetch(`/api/user/${userId}`);
const data = await response.json();
console.log(data);
};
fetchUserData();
return () => {
console.log('Cleanup code');
};
}, [userId]);
return <div>User ID: {userId}</div>;
}
Memoization is a technique used to optimize performance by caching the results of expensive function calls and reusing the cached result when the same inputs occur again.