Jonathan
Jonathan

Reputation: 469

props in functions not calling the function

I'm trying to fix a problem from the code and don't understand why is not working.

Function:

export const monthlyKpiActions_disp = (threeMonthsBefore, currentDate) => {
    console.log('kpppppppppppppppi')
    return monthlyKpiActions.fetch({
        filter: {
            objectId,
            interval: threeMonthsBefore + '/' + currentDate,
            names: [
                'ecostats_fuelusagetotal',
                'ecostats_fuelrefmileage',
                'ecostats_co2emission',
                'tripstats_mileage',
                'tripstats_drivingtime',
                'optidrive_indicator_8'
            ].join(',')
        },
        forceUpdate: true,
        resetState: false
    })
}

redux

function mapDispatchToProps(dispatch) {
	return {
		monthlyKpiActions_func: (threeMonthsBefore, currentDate) => dispatch(monthlyKpiActions_disp(threeMonthsBefore, currentDate)),
	}
}

calling the function

const currentDate = moment.utc().add(1, 'months').format(dateFormat)
const threeMonthsBefore = moment.utc().subtract(3, 'months').format(dateFormat)
{ () => this.props.monthlyKpiActions_func(threeMonthsBefore, currentDate) }

The problem is that never enters the function, any suggestions?

Upvotes: 0

Views: 17

Answers (1)

James
James

Reputation: 82096

That's because you never call the action, this line

{ () => this.props.monthlyKpiActions_func(threeMonthsBefore, currentDate) }

Creates a block scope with an anonymous function which internally calls your action, but its never invoked (nor makes any sense in this context).

Just call the action:

this.props.monthlyKpiActions_func(threeMonthsBefore, currentDate)

Upvotes: 2

Related Questions