标签云

微信群

扫码加入我们

WeChat QR Code

I am working on a application using Reactjs and Redux. I have a requirement, where I need to delete the item from list. Here the delete function works all good, but I need to give user an option to undo delete. My current method isreturn dispatch => {dispatch(deletePosts(postID));return fetch(API.url(postID), {method: API.type,credentials: 'same-origin'}).then(function(response) { if(!response.ok) {//revert back }});}Here I first delete the post from the state and then call fetch request to delete from server. But if I give any such feature to reverse, I can't just delete from server. I think it's reasonable to display undo option for probably 3 secs and perform the action. Can you please help me how I can achieve this and if any other web application has implemented this.Thanks


Hi Dan, thanks for the response. I guess myquestion wasn't very explanatory. The problem is I want to implement "Undo" feature. So if I delete the content from server "Database", I won't have anything to revert back to. So I am having difficulty to architect the "Undo" feature in asynchronous environment. Hope this explains better

2019年04月22日14分48秒

So long as you get a reference to the data before you make the call to the server, it doesn't matter. Even if the value is deleted from the store and the database, you still have a reference to the original value, which you can inject back into both.

2019年04月22日14分48秒

You are right but the problem is, there is no revert back on server, if you delete from database its final. So I want to control everything on client side and send final API call.

2019年04月22日14分48秒

Hi trashgenerator, thanks. It's similar to what I am trying to do. But I am not sure how can I call the cancel option. Can you please check this gist.github.com/Vivekbhusal/a62bc0dc88daf4c1008c

2019年04月22日14分48秒

Seems you didn't post your reducers. Can you please make jsfiddle?

2019年04月22日14分48秒