I am facing an issue where useEffect hook runs everytime the main object is being altered and not only when some of the object’s properties are being changed and I am having hard time fixing this let alone understanding why it does that.
useEffect(() => {
try {
if (state.toDate && state.fromDate && state.agency && state.vehicle) {
const ppd = calculateVehiclePrice()
setPricePerDay(ppd)
setPrice(ppd * getDaysInside() + state.additionalServicesSumTotal)
}
} catch (error) {
console.log(error)
}
}, [state.toDate, state.fromDate, state.agency, state.vehicle])
Here, the function is triggered when another property of state
object is being chagned, causing bugs