New Jun 12, 2025

UseMemo or Regular Variable Declaration in React

Libraries, Frameworks, etc. All from Newest questions tagged reactjs - Stack Overflow View UseMemo or Regular Variable Declaration in React on stackoverflow.com

Let's say I have a variable that depends on a prop, and I declare it in a simple way:

const isLeapYear = year % 4 === 0; // year is a prop

Now, let's imagine I have a complex function, and I "memorize" its result using useMemo:

const result = useMemo(() => console.log('complex function', isLeapYear), [isLeapYear]);

So here’s my question: Will result be recalculated every time just like isLeapYear, since isLeapYear changes with each render? Would it be a better idea to also declare isLeapYear using useMemo?

Scroll to top