DEV Community

Cover image for NextJS With Redux
YossefMohamed
YossefMohamed

Posted on

NextJS With Redux

Hey Guys,
I need a help :((
How can I use Redux With Nextjs , Is it recommended to use with the pattern of the NextJs ??
If there's any projects with NextJs and Redux can you give them to me to review the usage of the redux with next
Thanks in advance <3

Top comments (16)

Collapse
 
chandelieraxel profile image
Chandelier Axel

Hey !

IMO you almost never need any kind of state managing within your application. It doesn't really matter if it is Next.JS or plain React stuff.

Most of the use cases you may think about can be resolved without it :

  • Display UI changes ? I definitely not recommend it, this is what local component state are meant to do.

  • Share something globally within the app ? There's very few edge-cases, such as an user, or maybe a theme where I would use React.Context

Collapse
 
demkantor profile image
demkantor

While I agree context has come a long way and can now be used for global state management in many cases there are times that redux is the better solution. It all depends on the project.
Before I begin a project I go over the pros and cons of redux or context or nothing at all.
My last major next.js project I went with context, the prior one nothing, the one before that redux... Overall I'd say I use nothing or redux the most that is purely due to the types of projects I was doing.

Is redux worth learning? Mostly yes. Yes it needed? Depending on the project it will make life way easier or it will just add boilerplate and complications, only way to know is to learn it. And for learning I really recommend their docs, they are fantastic as far as docs go

Collapse
 
thomasskk profile image
thomasskk

If you use Redux Toolkit there is almost no boilerplate. Its simply redux but better.

Collapse
 
anh_vc_4d57caaa1f1cbd profile image
Anh Vũ Đức

Someone please tell me, do we really need redux for react project? Can we archive same state with react context? Or use SWR pack? I don’t want use redux, it look so complex :|

Collapse
 
merichard123 profile image
Richard • Edited

I agree redux is a lot of boilerplate code and to be honest you don't need redux. Lots of companies will be using redux but context will do just fine in most if not all cases.

I attempted to learn redux at one point but it was just too much for such basic tasks, I use a package called Zustand instead you'll find that things like this work just fine in all circumstances.

If you have started learning redux you can have a look at Easy Peasy it's a more simplified version :)

Good luck 🍀

Collapse
 
gomandev profile image
Gomandev

No matter how you try to run away from redux, redux is still the rockstar state management tool. But they are a new tool for redux that simplify stuff. We now have Redux Toolkit (redux-toolkit.js.org/). You might wanna check out. Cheers.

Thread Thread
 
merichard123 profile image
Richard

Sweet!! I'll have a look at that. Thank you!!

Collapse
 
talr98 profile image
Tal Rofe • Edited

There is no "You don't need redux". Because you do need it. Actually, I don't see any reason not to use redux over ReactContext.

The reason is simple, and I won't even explain:

My personal summary is that new context is ready to be used for low frequency unlikely updates (like locale/theme). It's also good to use it in the same way as old context was used. I.e. for static values and then propagate updates through subscriptions. It's not ready to be used as a replacement for all Flux-like state propagation.

This was being said by React member (github.com/facebook/react/issues/1...)

Thread Thread
 
merichard123 profile image
Richard

The best way to go about anything is just to use whatever you are comfortable with. If redux is the right solution for you then I'm not judging. Oftentimes redux is way too bloated and simpler replacements are much easier to implement and achieve the same task. Even when context won't work for example for state subscriptions like you said tools like Zustand allow for subscribing to state there is no need to reach for bloated tools like redux.

Redux is not the only solution to the forever expanding problem of state management. Hence I stand but it you don't need redux, however if you are comfortable with it by all means use it. I'm just saying you don't have to learn redux because all the "cool kids" are using it.

Collapse
 
chandelieraxel profile image
Chandelier Axel

Hi ! Just answered your question above 👆

Collapse
 
knitesh profile image
Kumar Nitesh

Hi Yossef,
Take a look at this repo github.com/oh-my-c0de/oh-my-fullstack. It has skeleton project with NextJs+ Redux

Collapse
 
sabz72608404 profile image
Sabz

Instead of implementing redux for the nextjs project... Consider react query... Look at the docs, it all you might need.
What is your use case?

Collapse
 
yossefmohamed profile image
YossefMohamed

If have no use case right now, I just start learning Next Js but I didn't find any course that use Redux with it

Collapse
 
gauravdh9 profile image
Gaurav Dhiman

Yeah there is no limitation to such like that.
But you should know your poison.
You should try redux-toolkit as well

Collapse
 
amrshadid profile image
Amr shadid

Hi Yossef
I hope you are safe and fine
Maybe this GitHub repository can help you
github.com/CodementorIO/nextjs-red...

Check it and tell us about your feedback please

Collapse
 
yossefmohamed profile image
YossefMohamed • Edited

Thanks very much Amr
That sounds helpful I am going to check it 👍❤️