From 7618422b65fb413b2ee69a1a787c986ab21e006e Mon Sep 17 00:00:00 2001 From: Scott Prue Date: Thu, 31 Aug 2017 01:17:44 -0700 Subject: [PATCH] Comments improved on react-redux-firebase example. --- docs/redux.md | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/redux.md b/docs/redux.md index 05dd9fc5..5649e508 100644 --- a/docs/redux.md +++ b/docs/redux.md @@ -27,7 +27,7 @@ To add `react-redux-firebase` to your project: export default makeRootReducer; - // Useful for injecting reducers as part of async routes + // *Optional* Useful for injecting reducers as part of async routes export const injectReducer = (store, { key, reducer }) => { store.asyncReducers[key] = reducer store.replaceReducer(makeRootReducer(store.asyncReducers)) @@ -55,17 +55,12 @@ To add `react-redux-firebase` to your project: // initialize firebase const firebase = RNFirebase.initializeApp(reactNativeFirebaseConfig); - const middleware = [ - // make getFirebase available in third argument of thunks - thunk.withExtraArgument({ getFirebase }), - ]; - const store = createStore( makeRootReducer(), initialState, compose( reactReduxFirebase(firebase, reduxFirebaseConfig), // pass initialized react-native-firebase app instance - applyMiddleware(...middleware) + // applyMiddleware(...middleware) // if using middleware ) ); return store; @@ -79,7 +74,7 @@ To add `react-redux-firebase` to your project: import React from 'react'; import { Provider } from 'react-redux'; import createStore from './createStore'; - import Todos from './Todos'; + import Home from './Home'; // Store Initialization const initialState = { firebase: {} }; @@ -87,7 +82,7 @@ To add `react-redux-firebase` to your project: const Main = () => ( - + ); @@ -198,6 +193,25 @@ Full source with styling available [in the react-native-firebase example for rea For more details, please visit [`react-redux-firebase`'s react-native section](http://docs.react-redux-firebase.com/history/v2.0.0/docs/recipes/react-native.html#native-modules). +#### Thunks +`react-redux-firebase` provides the `getFirebase` helper for easy access to Firebase helper methods. Using this feature is as easy as passing it in while creating your store: + + ```js + const middleware = [ + // make getFirebase available in third argument of thunks + thunk.withExtraArgument({ getFirebase }), + ]; + + const store = createStore( + makeRootReducer(), + initialState, + compose( + reactReduxFirebase(firebase, reduxFirebaseConfig), + applyMiddleware(...middleware) // pass in middleware + ) + ); + ``` + ## Standalone Integration Although the following example works for a basic redux setup, it may differ when integrating with other redux middleware.