My Expo App crashed in IOS device, Below is the code
I think it is beacause of AbortController and API call, can please anyone help in this?
useEffect(() => {
loadConfig(abortController)
return () => {
abortController.abort()
}
}, [])
const abortController = new AbortController()
const loadConfig = useCallback(async (abortController : any) => {
try {
let api_data = {} as configData
if(globals.org_id != undefined){
api_data.org_id = globals.org_id
}else {
let uData = await getUserData() as UData
api_data.org_id = uData.org_id
}
if(globals.selectedLevel != undefined){
api_data.lid = [globals.selectedLevel]
}else{
api_data.lid = [await getLevels() as string]
}
api_data.mac_id = [data.mac_id]
api_data.config_type = "config"
console.log(api_data,"--------------------------------->")
console.log(abortController,"****************************************")
let config_data = await getConfigData(api_data, abortController)
console.log(config_data,"config_dataconfig_dataconfig_dataconfig_data")
if(config_data.data.statusCode === 200){
let latest_config = config_data.data.result[0].latest_config
let old_config = config_data.data.result[0].old_config
for(let oc of object_config){
if(latest_config[oc] != undefined && latest_config[oc][oc] != undefined){
latest_config[oc] = latest_config[oc][oc]
}
if(old_config && old_config[oc] != undefined && old_config[oc][oc] != undefined){
old_config[oc] = old_config[oc][oc]
}
}
setConfigData((prevState) => ({
...prevState,
new_config: latest_config,
old_config: old_config,
prev_new_config: latest_config
}))
}else{
ShowToast({id: "error_config", status: "error", title: "Error", description: "Error"})
}
} catch (error: any) {
console.log(error,"Errorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
ErrorHandling(error)
}
}, [])
//In this before this line app get crashed
let config_data = await getConfigData(api_data, abortController)
const getConfigData = (data: configData, abortController: AbortController) => {
return authAxios.post('panel/configs/get_new', data, {signal: abortController.signal})
}
It is consoling till
console.log(api_data,”———————————>”)
console.log(abortController,”****************************************”)
Problem is that every time when controller.abort() is called the app crash without any error.
How to fix it?