I need to call the API after component Mount. but I am using Function Component. by that reason, I am using the useEffect hook like the following.
function ReportPage({ getAlertAuditLogs, getSensors, getUsers }) {
...
useEffect(() => {
getAlertAuditLogs()
getSensors()
getUsers()
}, [])
...
}
but I got the notification :
React Hook useEffect has missing dependencies: 'getAlertAuditLogs', 'getSensors', and 'getUsers'. Either include them or remove the dependency array. If 'getAlertAuditLogs' changes too often, find the parent component that defines it and wrap that definition in useCallback react-hooks/exhaustive-deps
the 3 apis don't have any param. How can I fix this issue?
PS : getAlertAuditLogs is the redux actions like the following
import { reportConstants } from "../_constants"
import { alertAuditLogsService } from "../_services"
export const reportActions = {
getAlertAuditLogs
}
function getAlertAuditLogs() {
return (dispatch) => {
dispatch(request())
alertAuditLogsService.getAlertAuditLogs().then(
(alertAuditLogs) => dispatch(success(alertAuditLogs.docs)),
(error) => dispatch(failure(error.toString()))
)
}
function request() {
return { type: reportConstants.GET_ALERT_AUDIT_LOGS_ALL_REQUEST }
}
function success(alertAuditLogs) {
return { type: reportConstants.GET_ALERT_AUDIT_LOGS_ALL_SUCCESS, alertAuditLogs }
}
function failure(error) {
return { type: reportConstants.GET_ALERT_AUDIT_LOGS_ALL_FAILURE, error }
}
}