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
Jump to solution
4 Replies
cje
cje10mo ago
no this is a totally normal way of using usestate
Solution
cje
cje10mo ago
usereducer exists for building a lil state machine where one action can update multiple things
cje
cje10mo ago
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
Matt
Matt9mo ago
Thanks!
Want results from more Discord servers?
Add your server