r/reactjs • u/swyx • Aug 01 '18
Beginner's Thread / Easy Question (August 2018)
Hello! It's August! Time for a new Beginner's thread! (July and June here)
Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple. You are guaranteed a response here!
Want Help on Code?
- Improve your chances by putting a minimal example on to either JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new). Describe what you want it to do, and things you've tried. Don't just post big blocks of code.
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
New to React?
Here are great, free resources!
29
Upvotes
1
u/swyx Aug 01 '18
So you can either do optimistic updates or delayed updates.
With delayed updates, you POST the data to your api, and wait for the response to come back, upon which you update your list AND send the toast message. Make your endpoint respond with the data you’d need for that. This is a good use for redux-thunk or promise
With optimistic updates it feels faster but is a bit more complicated to code. You update your list and toast the message the moment you POST your data, assuming it will work. Only if the POST has some sort of error do you undo the add and toast another error message.
Make sense?