Hacker News new | ask | show | jobs
by jeeeeefff 2904 days ago
I was surprised to see that this uses React without Redux for state management. I'm aware that Redux is a separate, optional, codebase, but from how people have been talking, it seemed like just about everyone was Redux or bust.

How many production-scale projects don't use Redux? Is this more common than I'm thinking and hearing?

8 comments

I wouldn't get too excited. This is just a shell app, a few screens, no remote data, only temporal state persistence and nothing really functions (eg no form validation, no payments etc).

I assume it was used for some tutorial?!

Not saying you can't get away with not using redux at all but this isn't an example of that. Try mobx or unstated for simple state management.

Personally my projects tend to use it because I'm used to it. Once you get your head around it the boilerplate is not too much to deal with and it slides in so nicely with react. You just need to think in a functional way.

Also features like redux-persist make it powerful. You wouldn't believe the number of apps released on the stores using RN that don't persist state and simply restart when the phone runs out of memory or gets rebooted.

Heh, when I saw UI, I was thinking-

So what?

Javascript, RN, flux, elements, etc... there are soo many ways to make it pretty. That was the whole point. Pretty for android and ios.

The redux tutorial is awful, you dont run the program until the very end. Needless to say, it didnt work and I ended up following a medium guide...

Now I'm trying to get redux working with laravel who requires a CSRF token on each post request. Not a big deal, but getting this CSRF token to be submitted doesnt seem to be trivial since it needs to be requested from the php and submitted all at once.

Not complaining because this is just logic and the job, but the difference between a working RN app and a working RN UI is 10 months.

Not sure what Redux would have to do with a CSRF token? That's HTTP logic.
Use jwt instead and treat laravel as a pure api backend.
Every app i've worked on for the last 3 years has fit in one of two categories:

1. Minimal use of Redux

2. Started with Redux, migrating to eliminating Redux.

This has mainly been due to using other technologies for dealing with API data (i'm using Relay, but there are other options), and having relatively little need for client-side state that can't be handled at the component level. When I have needed simple shared state, I just use the context API. If I absolutely needed a lot of client-side shared state, I might still consider Redux, but would also strongly consider client-side GraphQL extensions (both Relay and Apollo support these) so that everything follows the same patterns.

Is Apollo ready for true client side caching these days? I tried it on an app earlier this year with the belief that it would allow me to skip redux and simply keep client state synchronised with the server but without having to load it every time and walked away disappointed. The vision is great though!
As far as Apollo Client is concerned, I don't really know. I keep up-to-date with what's going on, but haven't really used it. Everything i've heard suggests there shouldn't be a problem, but Apollo is really good at marketing.

For Relay you're basically given no caching out of the box, but you can implement it by essentially hijacking the store's garbage collection to use an LRU cache instead of immediately evicting data when its dependents unmount. The developer experience for client-side schema extensions is similarly immature, but it is possible.

If you need all this functionality and aren't comfortable diving into the trenches, you'll have an easier time with Apollo (assuming everything works as advertised).

What were your negative experiences with Apollo? Been using it for a year and haven't had any issues.
I started with apollo-client on a new app, but switched to using ngrx and turning off apollo-client caching (basically using apollo-client as a fancy graphql request library - I should probably just use apollo-link directly). My main problem was that it felt like it required both developers and components to have too much knowledge of the individual queries that the app was making. Instead of writing an app that happened to use graphql, I felt like I was writing a graphql app.

An example of that is updating the state after mutations that modify lists (e.g. creates or deletes). It's up to the developer to remember all other queries that could be affected by a mutation and to update them manually after the mutation completes (more info: https://github.com/apollographql/apollo-client/issues/3505 and https://www.apollographql.com/docs/angular/features/cache-up...). If you add a new component that performs a query that could be affected by a previous mutation, you have to remember to also go back to that mutation and update your query from it. With ngrx (or redux), the consistency is baked in, and part of the beauty of it is that if you update the state, anyone who happens to be reading that state will get updated automatically.

I can see where updating the cache in all the right places for complex architectures could get hairy. For my own personal project, I'm using GraphQL Subscriptions to listen for mutations and piping those events directly to the client, which then updates the cache accordingly. I get that's not a solution for everyone as it would largely depend on your backend architecture having support for subscriptions.
Not negative as such, just didn't hit the mark that their marketing material was promising.

It's great for pull down refresh lists etc and I even had success doing dynamic insertion when an item in another view was updated (though I had to use a different graphql client to do the inserts ironically) but it was sold as replacing all need for redux for example for state management and that it would sync seamlessly with a graphql backend and unfortunately (maybe it was me) couldn't work out how to do that so ended up using redux as well.

What I was lead to expect is that you subscribe to a store which is dynamically filled and updated by Apollo (which handles synchronising local and remote and loading from scratch etc).

It might have had to do with the fetchPolicy that was in place. By default, Apollo aggressively uses local caching. But this is not always good. Ideally you could just subscribe to GraphQL subscriptions which would update your local stores, but I understand not all backend architectures are wired up that way. https://www.apollographql.com/docs/react/advanced/caching.ht...

Apollo has more advanced configuration options, and I think they're confusing to grasp at first. But I do think Apollo cuts down on the amount of state management you need to do for a typical app by about 2/3rds or more.

I personally used redux one time on a project and said, never again.
I wish, but I think my project is too big for me to avoid it.
Try MobX
Or unstated.
You can absolutely build React apps without Redux, often times however I find myself using Redux the most while communicating with the Api (Call out to the API, get some new data, put it into the Redux store, App rerenders) so if this is just a shell, then I'm assuming it would be fairly easy to get away with not using it.
We have three RN production apps, only one is using Redux because the developer was familiar with it, not because we necessarily needed it. The other two are using Apollo Link for client-side state.
Working on a new production app right now that does not use Redux, I do not plan on backwards integration either. For reference, our team does have two applications that utilize Redux.
We don't use redux. We are happy using js-data with a rest backend right now. We going to try graph-ql soon.