Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apollo 2 a replacement for redux?

Is Redux still relavant when using Apollo?

I have recently been diving into Apollo 2, and have seen a notable post stating that they have removed a lot of redux code in favor of Apollo.

https://dev-blog.apollodata.com/reducing-our-redux-code-with-react-apollo-5091b9de9c2a

I know that Apollo 1 used redux under the hood, but that has been deprecated in v2, and several sources have pointed to using apollo-link-state and Apollo Cache as a replacement.

The Apollo Dev tools are super useful but I find myself often wishing to use Redux Dev Tool to be able to see the application global state, use time-travelling and see all that actions called.

It may be that im still getting use to Apollo, but I wanted to know is there still an advantage to using Redux with Apollo?

Update I have found someone who has build a simple application using Apollo 2, which clearly makes me think think that Redux is completely unnecessary in Apollo.

https://hptechblogs.com/central-state-management-in-apollo-using-apollo-link-state/

like image 924
William Avatar asked Jan 03 '18 16:01

William


2 Answers

State management in a react application is a multi-dimensional issue. It involves coordinating/analyzing states of different components in your screen and managing asynchronous state + data flow (http, persistance, etc.). Apollo started out by only addressing the asynchronous state management. It abstracted away graphql http calls as internals of components. Redux started out on the other side by managing local synchronous state. Today though both solutions are able to provide a local and remote data state management implementation and could be considered interchangable.

The biggest difference between both solutions is the underlying state transition philosophy. Apollo requires less boiler plate by going against the idea of having pure state transitions. On the other hand, Redux follows more of a strict approach to ensuring stat transition occurs in a pure way. I personally like using Redux with GraphQl since Im a big fan of having my state being a result of a series of actions. It keeps things predicatable while still enabling GraphQl to be used by an async handling middleware like redux-saga or things of the sort.

TLDR: Apollo is simpler as it allows the library to do a lot of the async work but comes at the cost of not using Redux's awesome action command pattern.

like image 184
alaboudi Avatar answered Oct 01 '22 07:10

alaboudi


I have found someone who has build a simple application using Apollo 2, which clearly makes me think think that Redux is completely unnecessary in Apollo.

https://hptechblogs.com/central-state-management-in-apollo-using-apollo-link-state/

like image 38
William Avatar answered Oct 01 '22 06:10

William