Many companies and developers ask themselves this question if they start talking about managing data inside a react app. Usually, criteria are simple: easy to set up, easy to work with, decent documentation, large community. If we start considering relay and redux by these criteria which one will win? Let’s figure it out!
What is Relay?
Relay is a data manager from Facebook. It was initially built for react-native apps but later it became a tool for web apps as well.
The idea of Relay is simple: you app needs to fetch only data your users need. It’s declarative way of describing what data is needed. A simple relay query would look like this:
We ask for user’s first name and last name. The server will only return to us these two fields. No more.
Relay requires your server side to support query language requests.
What is Redux?
Redux itself is pretty simple and has only a few internal things(store, dispatch/action, reducer), everything else is your imagination. It is pretty solid and stable library with a huge community over the world.
Redux doesn’t have any features like Relay has. Whatever you want from Redux you have to build yourself(or find it in GitHub). You decide how to fetch, what data to fetch, how to store it and how to update it. Redux doesn’t require anything from your server side, it only requires you to follow simple rules.
When to use Relay?
When to use Redux?
Which one should you choose?
Of course, it depends on an app you are building, in one hand we have Relay:
and in another hand we have Redux:
It is absolutely up to you which one you pick. This kind of decisions has to be made in the begging of development so be careful with your desires.
Whether you use relay or redux or any other tools it only matters how you use them. There is no bad tool or language there are wrong decisions make at the very first place. You can always use Relay with Redux, as I do. I use Relay to store business data and Redux for some temporary things such as themes, locales, filters.
Like the story? Share & Clap it. Thanks.