Update and delete problem in mern stack

HELLO Everyone,

I am facing some problems in my mern stack. I have implemented redux too. I want to make a crud app actually. here, in the Post.js file in client’s component folder I have made delete fucntionality. If I click on Delete the post deletes that’s good, But I want if I click on Delete this should be redirected to the Post lists "/" page. I wanted to do this with componentDidUpdate but this is not working.
Another Problem I am facing that I cannot display my Update page which is UpdatePost.js in components folder. It only goes to the link but the content is not showing at all where I want to update the whole post.

Please help me fix my problem.

The github repo -

React Router and history.push

sorry i couldn’t understand what u r saying. can u be more specific ?

1 Like

ok. but the update functionality ?

but i think component lifecycle would be more nicer

componentDidUpdate() (CDU) does give you a lot more control over the lifecycle but I’m not sure why you’d need it for this simple task. To use CDU you have to know specifically the props or state change that you want to act on, CDU has the previous props and previous state as arguments, you compare either one of those to the current state or current prop and perform your action, roughly,

     // compare the props before and after to see when/if an update has occured, ex.
    if(this.props.post.description !== prevProps.post.description){
        // do something
1 Like

Dereje1 brother, I want to try to make a crud like blog site. that is why I am trying to make such things. I want that in the full post page there will be delete and update options. If anyone deletes it , it will redirect to home page like this… though my update page is not showing anything.

I don’t understand the problem, you want to redirect using router ?, where to?, you can reload the entire root route with window.location.assign('/') , It is not clear to me what you are trying to do.

Bro, I actually want if anyone deletes any post, then after deleting it, the page will be redirected to ‘/’ page. This thing. And If anyone wants to update the post, then after clicking the update button, the page will go to its update page, and when update is finished, it will be redirected to its full single post page. This function. But my update page is not showing anything where I made also update forms like add post forms.

And I gave you the solution to how to redirect.

Did you read my link?
I don’t think so, because there are many posts and stackoverflow questions about this topic.


user clicks delete button
change state of blog posts
redirect to new path
1 Like

yes. thank you. I will make the full project freshly again.