joschan21 / breadit

Modern Fullstack Reddit Clone in Next.js 13 & TypeScript
1.06k stars 261 forks source link

fix: onError logic #32

Open Smootw12 opened 8 months ago

Smootw12 commented 8 months ago

Hey Josh,

If a previous user vote exists and the vote for which the request failed is the opposite of the previous one, you need to reset the votesAmt twice! Essentially, it has to be like the onMutate logic but inverted. However, I found a shortcut by using the onPrevious hook, and it makes the code more readable too!

P.S: Please be patient; this is my first pull request! Love the content, by the way <3!