Comments improved on react-redux-firebase example.

This commit is contained in:
Scott Prue 2017-08-31 01:17:44 -07:00
parent 5662f592e2
commit 7618422b65
1 changed files with 23 additions and 9 deletions

View File

@ -27,7 +27,7 @@ To add `react-redux-firebase` to your project:
export default makeRootReducer; 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 }) => { export const injectReducer = (store, { key, reducer }) => {
store.asyncReducers[key] = reducer store.asyncReducers[key] = reducer
store.replaceReducer(makeRootReducer(store.asyncReducers)) store.replaceReducer(makeRootReducer(store.asyncReducers))
@ -55,17 +55,12 @@ To add `react-redux-firebase` to your project:
// initialize firebase // initialize firebase
const firebase = RNFirebase.initializeApp(reactNativeFirebaseConfig); const firebase = RNFirebase.initializeApp(reactNativeFirebaseConfig);
const middleware = [
// make getFirebase available in third argument of thunks
thunk.withExtraArgument({ getFirebase }),
];
const store = createStore( const store = createStore(
makeRootReducer(), makeRootReducer(),
initialState, initialState,
compose( compose(
reactReduxFirebase(firebase, reduxFirebaseConfig), // pass initialized react-native-firebase app instance reactReduxFirebase(firebase, reduxFirebaseConfig), // pass initialized react-native-firebase app instance
applyMiddleware(...middleware) // applyMiddleware(...middleware) // if using middleware
) )
); );
return store; return store;
@ -79,7 +74,7 @@ To add `react-redux-firebase` to your project:
import React from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import createStore from './createStore'; import createStore from './createStore';
import Todos from './Todos'; import Home from './Home';
// Store Initialization // Store Initialization
const initialState = { firebase: {} }; const initialState = { firebase: {} };
@ -87,7 +82,7 @@ To add `react-redux-firebase` to your project:
const Main = () => ( const Main = () => (
<Provider store={store}> <Provider store={store}>
<Todos /> <Home />
</Provider> </Provider>
); );
@ -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). 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 ## Standalone Integration
Although the following example works for a basic redux setup, it may differ when integrating with other redux middleware. Although the following example works for a basic redux setup, it may differ when integrating with other redux middleware.