Hacker News new | ask | show | jobs
by borplk 3296 days ago
Redux state is useful for when other parts of the app need to be aware of or react to that state.

Sometimes there are little bits and pieces that may look like they are "private state of a component" but over time you'll find instances where it's useful to know that state.

For example I have a LoginForm component and a SignupForm component.

If you have half-way filled email and password on the LoginForm, but click on "Create an account" it would be nice if SignupForm picked up that state from the login form.

So my LoginForm state is stored in the redux store under the key "loginForm".

And SignupForm will pick up that state if available and vice-versa for going from sign up to log in.

1 comments

For this specific occasion you could also use the Lift state up pattern -> https://facebook.github.io/react/docs/lifting-state-up.html and it would work just as fine.

I've been doing some React projects for the past 6-7 months and I still haven't had the need to use Redux. I believe you want Redux when your application is really large / complex.

Yes but it can get pretty noisy when a component that is deep down needs access to some information.

Redux decouples component structure from information access.

This is useful when you have some little button for example that should look different depending on whether the user is logged in or not.

Without redux you will burden each and every component in the hierarchy to manage that state up and down.

With redux that button can hook itself into the state and be dropped anywhere without burdening its parents for any state management.