Theo's Typesafe CultTTC
Theo's Typesafe Cult2y ago
7 replies
Matt

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
usereducer exists for building a lil state machine where one action can update multiple things
Was this page helpful?