Amplify-js: Amplify and Redux?

Created on 4 Sep 2018  路  3Comments  路  Source: aws-amplify/amplify-js

This is really more a question out of curiosity that I am hoping someone more experienced could comment on. But is Redux necessary with AmplifyJS? I notice that Amplify has Cache and Hub messaging utilities which could be used for Redux like behavior. Is the purpose of those utilities related to that in anyway? Or is it still appropriate and ideal to pull Redux in an AmplifyJS web app?

question

Most helpful comment

Here is a small example of integrating Redux with Amplify in an web app: Step 05 - State Management via Redux

All 3 comments

I think it depends on the requirements of your app.

It may be an obvious point, but Redux isn't needed (or even perhaps desirable) for simpler apps. The basic dispatch/reduce/select functionality can be trivially implemented with recompose for small/simple apps (https://github.com/acdlite/recompose/blob/master/docs/API.md#withreducer).

The value of Redux IMO is the ecosystem of middleware and enhancers. For a more involved app, side effect management (e.g., redux-saga) is very desirable. Similarly, redux dev tools browser extension is a powerful tool for debugging larger apps.

I wouldn't suggest it unless you know you need it, but we are using them together such that when a Hub event is dispatched, a Redux event is also dispatched and optionally handled by a reducer or saga:

const store = createStore(...)

store.onHubCapsule = ({ channel, payload: { event, ...payloadFields } }) =>
        store.dispatch({
            type: `@@amplify/Hub/${channel}/${event}`,
            payload: payloadFields,
        })
Hub.listen('analytics', store, 'ReduxStore')
Hub.listen('auth', store, 'ReduxStore')
Hub.listen('storage', store, 'ReduxStore')

Here is a small example of integrating Redux with Amplify in an web app: Step 05 - State Management via Redux

@rygo6 - Closing this issue as your question seems to have been answered. Please feel free to reopen it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cosmosof picture cosmosof  路  3Comments

lucasmike picture lucasmike  路  3Comments

TheRealRed7 picture TheRealRed7  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

DougWoodCDS picture DougWoodCDS  路  3Comments