How to perform a logic on completion of the useAutoComplete ? #4214
-
I am using useAutoComplete to call a couple of services which fetch data from db. Now i have a dropdown that should contain the some filtered values based on a logic obtained from the useAutoComplete calls. I have tried using the logic inside the useEffect but it runs even before useAutoComplete is finished. When i add the autoCompleteProps returned from useAutoComplete as dependency , the useEffect keeps on executing like continuously. can someone help me in getting this work?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Are you only using useEffect(() => {
const currentServiceDetailIds = questionsData?.serviceDetails;
if (!currentServiceDetailIds || currentServiceDetailIds.length == 0) {
return;
}
const currentServiceDetail =
serviceDetailAutocompleteProps.options?.find((serviceDetail) => {
return serviceDetail.id == currentServiceDetailIds[0];
});
if (!currentServiceDetail) {
return;
}
const currentService = serviceAutocompleteProps.options?.find(
(service) => service.id == currentServiceDetail.serviceId,
);
setValue("service", currentService);
}, [questionsData?.serviceDetails, serviceDetailAutocompleteProps.options]); |
Beta Was this translation helpful? Give feedback.
Are you only using
serviceDetailAutocompleteProps.options
inside theuseEffect
? Have you tried adding onlyserviceDetailAutocompleteProps.options
to the dependency array to see if it solves the issue?