I am working on my React skills and I would appreciate if you recommend me a better way of writing React code.
Here is a simple task I am currently working on: https://codepen.io/cjanes/pen/qBVaPZx?editors=0011
As you can see, in order to calculate the total price of the checked products, I need to get the array checkedItems. I choose to keep track of it inside a useEffect in TotalPrice component.
The problem is this: The TotalPrice component gets re-rendered twice, first with the last value, and then with the new calculated value.
How can I refactor my code so that it is more optimized?
useEffectcan beuseMemowhich has one less render cycle.