timofeysie / redux-typescript-example

A small social media feed app based on the Redux essentials code using TypeScript and unit tests.
12 stars 8 forks source link

produce() function needed in postAdded reducer? #6

Open jonathan-graf opened 1 year ago

jonathan-graf commented 1 year ago

I must start off this report by saying what an absolutely fantastic repository this is. You've done a remarkable job at breaking down rather complicated concepts and creating a reusable guide for all sorts of systems. You are a wonderful human.

Regarding the postAdded reducer, I understand that you are using a prepare() callback, so there is a reducer() callback as well. However in this doc, it says that createSlice uses createReducer which users immer so state changes can be "mutated" inside the function. What is your experience here? Did you add the immer produce() function for a reason?

timofeysie commented 1 year ago

HI @jonathan-graf , that's a pretty good fine. From my git commit message it seems that was added while converting part 6 to use TypeScript. Now, I'm not sure why I did that. From the timing, it's possible that's when I started to use ChatGPT to speed things up a bit.

This was a learning exercise for me, as I was about to start a role using Redux and Typescript and wanted to use Redux Toolkit. So this repo was an attempt to get some experience with it.

I don't think actually that reducer is being used anywhere, so it must have been some experiment that slipped in to the codebase. I was trying to setup authentication so that I could host the app somewhere as a real world example, but I kind of ran out of time. Also, since React stopped supporting create-react-app, and there is a new version of the Toolkit 2.0, I think this whole repo needs to be re-done from scratch, which I will attempt. Probably this will be based on a vite starter.

What has your experience with Redux Toolkit and Typescript been like?