The code will run, but that's not what a reducer is supposed to be doing.
Persistence logic like that should really be not be in a reducer - it should be at the store setup level, or possibly at the UI level. In this case, it could be done with a simple store.subscribe() call, in a middleware, or similar.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, I'm a Redux maintainer. Always glad to see new tutorials showcasing Redux Toolkit!
I do see one small issue I want to point out. In this snippet,
localStorage.setItem()
is technically a side effect:The code will run, but that's not what a reducer is supposed to be doing.
Persistence logic like that should really be not be in a reducer - it should be at the store setup level, or possibly at the UI level. In this case, it could be done with a simple
store.subscribe()
call, in a middleware, or similar.