You are updating your state wrongly, your code:
console.log(response);const newPost = Object.values(response.data);this.setState({ post: newPost });//this will update the state with new valuesconst updatedPosts = posts.push({title:post.title,content:post.content});//here you arepushing the new values to the existing postsconsole.log(post);console.log(updatedPosts);console.log(this.state.posts);
Desired code:
console.log(response);const newPost = Object.values(response.data);this.setState({ posts: [...this.state.posts, {title:post.title,content:post.content}]});console.log(post);console.log(this.state.posts);
This way it will update your state after updating the posts array.