I am using antd library for Tabs - https://ant.design/components/tabs/
In this onchange function I am doing some operations and updating the state finally.
Like this
<Tabs defaultActiveKey="1" onChange={this.getVariablesForSelectedTab}>
but I keep getting this error I am facing this error
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
But I already tried this fix Can't perform a React state update on an unmounted component It also didnt help, same error showing.
Here is what my function is internally doing -
getVariablesForSelectedTab = (key: any) => {
this.getAllItems(key.toString())
}
getAllLineItems = (key: string) => {
let ds: Data[] = []
if (key == "2") {
disputes = this.state.filteredDisputes.filter(dp => dp.status == "VERIFIED")
} else if (key == "3") {
ds = this.state.filteredDisputes.filter(dp => dp.status == "AP_REJECT")
} else if (key == "4") {
ds = this.state.filteredDisputes.filter(dp => dp.status == "APPROVED" || dp.status == "REJECT")
}
let rIds: string[] = []
ds.map(dp => {
dp.rId && rIds.push(dp.rId)
})
this.getLineItemsForResolutionIds(rIds)
}
Api calling function -
getLineItemsForResolutionIds = (rIds: string[]) => {
this.setState({ loading: true })
let formData = new Object()
formData["rIds"] = rIds
this.API.createRequest({ //this is a internal library which is used to call to local api server
path: `/xyz/lineitems`,
request: {
method: 'POST',
body: JSON.stringify(formData),
headers: { 'Content-Type': 'application/json' }
},
response: (response: ItemsResponse) => {
this.setState({ allLineItems: response.lineItems, loading: false })
}
})(this)
.catch((e: any) => {
this.setState({ loading: false })
notification.error({ message: "Error Fetching data" })
})
}