Can anyone guide me on the order of execution in this peice of Javascript code? Also, how is it that posts gets a deep copy of this.state.posts?

Viewed 25

Can anyone guide me on the order of execution in this piece of JavaScript code? Also, how is it that posts gets a deep copy of this.state.posts?

handleDelete = async (post) => {
    const posts = this.state.posts;
    this.setState({posts: this.state.posts.filter((p) => p.id !== post.id)});

    try {
        await Axios.delete(endPoint + '/' + post.id);
    } catch (error) {
        alert(error);
        this.setState({posts});
    }
};
0 Answers
Related