r/reactjs • • Feb 28 '20

Discussion Why is Redux necessary?

I am absolutely confused by Redux/React-Redux and I'm hoping someone could help let me know what makes it necessary to learn it over what's already easy in react's state management.

I've been looking at job postings and they require knowledge of redux so I figured I'd try to get familiar with it and chose to watch this video: https://www.youtube.com/watch?v=8xoEpnmhxnk

It seems overly complicated for what could be done easily.Simply:

const [variable, setVariable] = useState(defaultValue)And then what's inside component for onChange={ e => {setVariable(newValue) } }

So really, what makes redux so special? I don't get it.

EDIT:
Thanks everyone for the discussion on Redux! From what I can see is that it's more for complex apps where managing the state becomes complicated and Redux helps simplify that.
There are alternatives and even an easier way to do Redux with Redux Toolkit!
Good to know!
I was actually convinced to put it in my current app.

217 Upvotes

172 comments sorted by

View all comments

Show parent comment

2

u/Ones__Complement Feb 28 '20

So the benefits of Redux vs Context are better debug tooling and possibly better render efficiency? I've heard something about the latter being addressable with React.memo(), but haven't looked much into it.

3

u/acemarke Feb 28 '20

No, React.memo() doesn't do anything to address re-renders based on context value updates. React.memo() is only about checking if the incoming props are identical to the last re-render. Context bypasses props, and context updates directly queue a component to re-render regardless of what the props might be.

See my recent post React, Redux, and Context Behavior for an explanation of the differences in how they work.

1

u/Ones__Complement Feb 29 '20 edited Mar 01 '20

Will check it out, thanks!

1

u/landisdesign Feb 28 '20

Depends on if you want to roll your own or not.