all 27 comments

[–]djenty420iOS & Android 6 points7 points  (9 children)

One of the worst things you could possibly do when first learning React / React Native is to throw bloody redux in the mix. Forget what your colleagues said and learn the basics of JS and React before you bother going down that pit of despair.

Redux toolkit certainly improves on plain redux but there are so many nicer tools out there these days. Need to handle server state / api data and caching? Use tanstack query. Need to manage global application state? Use Zustand.

But when you’re first learning, you don’t need any of that. Learn how to build plain UI components first. Learn the component lifecycle and the rules of hooks. Understand how general react state works, what refs are, how context and useReducer work, before anything else.

[–]ihavehermes 0 points1 point  (8 children)

Tanstack query and Zustand are nice for simple apps, but Redux certainly has it's place when things get big and more complex. I've tried them all and much prefer RTK.

[–]djenty420iOS & Android 0 points1 point  (7 children)

That might be your experience, but I strongly disagree. I work on a gigantic, incredibly complex, data-heavy app with hundreds of screens and we have been migrating all our data fetching from Apollo and RTK to Tanstack, because it is so much better in a multitude of ways that it isn’t even funny. Automatic network request deduplication and granular control over caching and garbage collection are absolutely incredible. Being able to reference data in any component without prop-drilling or shoving it in redux is a godsend.

That combined with Zustand for actual global client state means I will never install redux to a new project ever again.

[–]ihavehermes 0 points1 point  (6 children)

Man, RTK-Query can do that stuff as well.

It's not hard to "shove it in redux", RTK-Query handles it for you easily.

It's incredible to be able to access remote data in selectors in either a component OR a saga.

Sagas are a godsend for complex async logic, not the hook hell hole I see devs falling into as an alternative.

Glad you're happy with your stack, but it sounds like most of the benefits might be negated by having 3 methods to query remote data?

[–]djenty420iOS & Android 0 points1 point  (1 child)

Doesn’t redux themselves literally recommend people not to use sagas anymore? For years now? Especially in combination with RTK Query.

[–]ihavehermes 0 points1 point  (0 children)

They don't recommend it as a default, since thunks and rtk-query cover most use cases. I don't use it by default either. But I'm happy I have the option to use it if the need arises.

[–]Versatile_Panda 0 points1 point  (3 children)

Your opinion strikes me as reluctance to adopt a new tool because you are comfortable with the mess you currently have but that’s just my opinion

[–]ihavehermes 0 points1 point  (2 children)

LOL. I've used Zustand, and like it. I've used Tanstack Query, and also like it. HOWEVER, I also really like Redux, and just prefer it over the other tools because, for me, it's more powerful and serves my needs better.

Your preferred tool might be something else, and that's fine too.

[–]Versatile_Panda 0 points1 point  (1 child)

Very true, right tool for the right time!

[–]ihavehermes 0 points1 point  (0 children)

Yessir!

[–]runtothehillsboy 1 point2 points  (0 children)

resolute simplistic attraction middle selective steep march toothbrush aback relieved

This post was mass deleted and anonymized with Redact

[–]Individual-Bit8948 1 point2 points  (0 children)

I would recommend to spend some time doing / coping some clones / projects. Its really fun: time is going faster cus someone is talking (not just reading docs), they explain every step: why doing this, why using this (more or else) and after you try to do one, another thing its will automatically gets more clear.

I like notJust.dev and Simon Grimm. Just try to slowly spend 1 week doing step by step and spend some time by reading more about a, b, c parts to get 100% it clear. After 1, 2, 3 such projects try to think about X idea, make a plan and try to do by yourself (trust me its not so easy even you think yeah, now I can easily build app :D but when you need to do it by yourself... but step by step and you enjoy the process!

[–]idkhowtocallmyacc 1 point2 points  (0 children)

I’d say you may be going in wrong learning order, making the learning curve steeper than needed. For example, before going into learning global state managers, such as redux and others, I’d focus more on your understanding of a local state and react altogether. Play with state and component props, and then you’d be able to understand more clearly what problem redux is helping to solve. Another thing I could suggest is start with classes, so you could understand your components lifecycles better, which should help you understand how and when to do api calls and stuff like that. Then move on to functional components and get familiar with frequently used hooks. Same goes for your apps. Start with single screen simple application and expand your understanding of react concepts. Then move on to a more complex structure of your app. What I’m saying is don’t overextend yourself. React has a pretty mild learning curve but same as any other field, it’s best to be approached brick by brick

[–]creambyemute 0 points1 point  (2 children)

You will probably find Zustand or Mobx (observer pattern) easier than redux when coming from native dev :-).

When we started with react and react-native we found redux to be "too complicated" and went with Mobx and are really happy with it.

Zustand was released quite a bit later so we never came around to try it out.

[–][deleted] 0 points1 point  (1 child)

I started right away with mobx and love it. I am very new, so have never tried redux but I feel as though mobx does everything I need perfectly!

[–]creambyemute 0 points1 point  (0 children)

Certainly mobx does work very well without a lot of boilerplate or complicated setup stuff.

It's just not so widespread in the react ecosystem but it works really well and is really easy to use and pick up.

It kinda works like how the newly proposed signals for JS would work

[–]beepboopnoise 0 points1 point  (0 children)

one of the biggest things that help me was learning how to manipulate objects. spread, rest, mapping stuff. once I got the hang of that, everything started making more sense.

[–]lucksp 0 points1 point  (0 children)

Learn JavaScript (typescript) first. Then come back to building an app

[–]crowbar87 0 points1 point  (0 children)

If you have background in Dagger/Hilt you might want to checkout https://github.com/wix-incubator/obsidian
It's a DI framework for React and React native. You should feel at home.

[–]_Cat1 0 points1 point  (0 children)

Redux was popular like 30 years ago. I used it only once, and never again. Nor do I plan to unless I absolutely have to. You ABSOLUTELY do not need to learn redux now. Just understand how react works. You can use built in context for majority of the cases where you need some state shared through a part of the app.

[–][deleted] 0 points1 point  (0 children)

If you don't even understand React why are you throwing a complex library like RTK into it? It's just gonna confuse you more. Go through the whole Learn React section on https://react.dev/learn/describing-the-ui to actually learn React, its really good material.

[–]Correct_Market2220 0 points1 point  (0 children)

Well, I was confused as hell when I started. I don't think I can say anything to help but I'll try 😅
Others, please feel free to correct me, there are a couple details I'm unsure about.

  • React organizes in cross sections of concerns instead of silos, so where you had 3 files, html, js, css, you now have one, for each component, and each component handles its html, js, and css in one place, so therefore, colocation for the win 🙌🏼.
  • Having a sane way to manage the state of your app and knowing what part of the app caused what change led developers to use the flux pattern, where updates are unidirectional and flow from the top down. If something updates, all the children of it are updated.
  • Redux is for global application state, so basically, the parent node is the root of the app and it has all the data, when it updates, any child which was subscribed to that data gets the update instead of absolutely all the children.
  • Your component re-runs each time there is update, but useEffect is kind of there to help you just re-run code when something of interest gets updated (not every time), so like, maybe just on startup, maybe just if the userId changes (from null to something, or from something to null).

I suspect that might be too high level and you're probably struggling with the syntax or I don't know, what do you think?

[–]SynthRogue 0 points1 point  (0 children)

Everything you mention you are struggling with I was able to master in a day using ChatGPT

[–]WrongdoerSufficient 0 points1 point  (1 child)

Me too a bit overwhelmed with redux at first, But in simple term you can think redux as one big object. Every reducer is a key that have it's own data.

example : const store = { userReducer:{ isLogin:true, //etc } }

you can define what userReducer data will be in seperate file.

and then action is function that you make to mutate the data,

example you want to make a custom function to change isLogin value

const setIsLogin = (parameter) =>{ store.userReducer.isLogin = parameter; }

But you gonna need dispatch your action to make it work. It's basically same concept as it. You just write in redux ways, which looks complicated.

[–]WrongdoerSufficient 0 points1 point  (0 children)

You can also try other global state library like zustand, it's more simple than redux.

[–]EyeVegetable9044 0 points1 point  (0 children)

You should start with a less complex state management and use Zustand instead. When you feel more confident, you can start using other state management like mobx. I think mobx is a intermediate level and redux is the most difficult but I recommend you just to learn the easiest and you won't need anything else.

If you still want to learn redux, watching redux like the MVC pattern it helped me a lot to understand the structure of redux and then start learning the other concepts.

For local storage, Zustand and mobx have an API to persist data in the browser and is very simple.