Have I been re-inventing useReducer or Redux?
I am relatively new to React. Whenever I am using an array of objects as a state variable, I've been doing things like this to change just one object at a time:
setCoords((prev) => [
...prev.filter((item) => item.id !== "draggable" + index),
newCoords,
]);
A job I am applying to mentioned reducers so I looked up useReducer and Redux and it seems like they exist pretty much to solve this kind of problem (rather than having the filtering in the call to setCoords, I could have that in a reducer function or Redux might just do all that more or less for me). Is that correct?
Solution:Jump to solution
usereducer exists for building a lil state machine where one action can update multiple things
4 Replies
no this is a totally normal way of using usestate
Solution
usereducer exists for building a lil state machine where one action can update multiple things
redux is basically the same but aimed at global state
of course any of these things can be used for things they werent intended for
Thanks!