Reputation: 43
i have issue when page loads it calls api one time, after user changes date it calls api again to change data to that date but it keeps old api alive and adding new one also, with this page gets very slow,
this is api when page loads
this is api when date updated two time
this is code when i call api on page load
componentDidMount() {
this.fetchData(this.state.startDate, this.state.endDate);
}
this is code every time i update api
updateDate = (start, end) => {
this.setState({startDate: start})
this.setState({endDate: end})
this.fetchData(this.state.startDate.startDate, this.state.endDate.endDate);
}
Upvotes: 0
Views: 581
Reputation: 9
Correct way is to use this.setState({object}
, callBack after state is changed)
this.setState({startDate: start, endDate: end}, this.fetchDate(startDate,endDate))
You need to club these two lines to one .
this.setState({startDate: start})
this.setState({endDate: end})
to
this.setState({startDate: start, endDate: end})
Upvotes: -1
Reputation: 8422
history
fetch that you calledThis means that they are not all alive but rather history records, it's only alive
in your term if they are having status pending.
You would need to check for a performance issue somewhere else, such as server response time or re-rendering of components.
Here is a pending status:
Upvotes: 4