Let's say I have the following heavy calculation function:
function heavyCalculator(str:string):string{
//Do some heavy calculation
return result;
}
function SomeComponent({prop1,prop2,prop3,prop4}:Props){
useEffect(()=>{
const result = heavyCalculator(prop3);
//How should i store the result?
},[prop3])
return <span>{resultFromHeavyCalculation}</span>;
}
How should I store the calculation result in a way that it won't get recalculated on every render / prop change?
Should I use "useMemo" or use "useState" and set it inside the "useEffect" only when prop3 is changed?