Skip to content

Commit fb6c255

Browse files
authored
* feat(HOCs): add error if using `react-redux@^6` (points to [v3 migration guide](http://docs.react-redux-firebase.com/history/v3.0.0/docs/v3-migration-guide.html)) - prescottprue#591 * fix(docs): update react-native section of docs including broken links - prescottprue#586
1 parent 83be2f4 commit fb6c255

File tree

8 files changed

+97
-80
lines changed

8 files changed

+97
-80
lines changed

docs/integrations/react-native.md

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ Regardless of which path you want to take, initial setup is the same, so we will
66

77
**NOTE:** Make sure you include `enableRedirectHandling: false` when using react-native with `v2.0.0`. This is required to disable redirect handling (which uses http) since it is not supported in react-native. There has been discussion of a way to make this happen automatically, but for now it is required.
88

9+
## JS/Web
10+
11+
Setup and use `react-redux-firebase` as normal (described in the [use section of the README](https://github.com/prescottprue/react-redux-firebase#use)). Since Firebase is initialized outside of react-redux-firebase, the automatic handling of react-native done by Firebase works.
12+
13+
[react-native complete example app](https://github.com/prescottprue/react-redux-firebase/tree/master/examples/complete/react-native)
14+
15+
**NOTES**
16+
17+
* Only works for versions `v2.0.0` and higher. For older versions please view the docs associated with previous version.
18+
* Will not perform as well as using native modules since the render thread is used for all JS
19+
920
## Native Modules
1021

1122
Passing in an instance also allows for libraries with similar APIs (such as [`react-native-firebase`](https://github.com/invertase/react-native-firebase)) to be used instead:
1223

13-
1. Follow [use instructions in README](http://react-redux-firebase.com/#use)
24+
1. Follow [use instructions in README](https://github.com/prescottprue/react-redux-firebase#use)
1425
1. When creating redux store pass `react-native-firebase` App instance into `reactReduxFirebase` when creating store:
1526

1627
**createStore.js**
@@ -48,40 +59,12 @@ Passing in an instance also allows for libraries with similar APIs (such as [`re
4859

4960
Full `react-native-firebase` example app source with styling available [in the react-native-firebase complete example](https://github.com/prescottprue/react-redux-firebase/tree/master/examples/complete/react-native-firebase).
5061

51-
### Setup
52-
1. Run `create-react-native-app my-app`
53-
1. Enter the app folder `cd my-app`
54-
1. Run the eject command `yarn run eject` or `npm run eject` and choose "Regular React Native App"
55-
1. Run `npm i --save redux react-redux react-redux-firebase@canary redux-thunk`
56-
1. Open the xcode project in ios/myapp
57-
* Drag the `GoogleService-Info.plist` into the project -> check box saying copy
58-
* switch the identifier to the one you just gave Firebase
59-
1. Follow the [react-native-firebase initial setup guide](http://invertase.io/react-native-firebase/#/initial-setup)
60-
61-
## JS/Web
62-
63-
**NOTE**: Only works for versions `v2.0.0-alpha` and higher. For older versions please view the docs associated with previous version.
64-
65-
[react-native complete example app](/examples/complete/react-native)
66-
67-
Instantiate a Firebase instance outside of `react-redux-firebase` then pass it in as the first argument like so:
68-
69-
**NOTE**: If you are looking to use native modules (`react-native-firebase` or other), [visit the `v2.0.0` docs](http://docs.react-redux-firebase.com/history/v2.0.0/docs/recipes/react-native.html#native-modules)
70-
71-
## Setup
72-
73-
1. Click "Add Firebase To iOS"
74-
<!-- TODO: Confirm this and get a picture -->
75-
1. Download `GoogleService-info.plist`
76-
1. Place `GoogleService-info.plist` in the folder of whichever platform you are using (i.e. `/ios`)
77-
1. Copy your client id out of the `GoogleService-info.plist` file (should end in `.apps.googleusercontent.com`)
78-
1. Place the client id into `iosClientId` variable within the example
79-
8062
## Creating Your Own
8163

8264
We are going to use the project name Devshare for example here. For your project, use your project name everywhere where Devshare is used.
8365

8466
### Start
67+
8568
1. Make sure you have [`create-react-native-app`](https://github.com/react-community/create-react-native-app) installed, or install it using `npm install -g create-react-native-app`.
8669
1. Run `create-react-native-app Devshare` (again replace Devshare with the name of your project)
8770
1. After that is complete, eject using `yarn eject` or `npm run eject`

package-lock.json

Lines changed: 49 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "2.2.4",
3+
"version": "2.2.5",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ export const supportedAuthProviders = [
239239
*/
240240
export const topLevelPaths = ['auth', 'profile', 'ordered', 'data']
241241

242+
/**
243+
* @constant
244+
* @description Error message shown if runnning react-redux v6 with a v2.0.0 version
245+
* of react-redux-firebase
246+
* @type {String}
247+
* @private
248+
*/
249+
export const v3ErrorMessage =
250+
'Context from react-redux not found. If you are using react-redux v6 a v3.*.* version of react-redux-firebase is required. Please checkout the v3 migration guide: http://bit.ly/2SRNdiO'
251+
242252
export default {
243253
actionTypes,
244254
defaultConfig

src/firebaseConnect.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isEqual, differenceWith } from 'lodash'
44
import hoistStatics from 'hoist-non-react-statics'
55
import { watchEvents, unWatchEvents } from './actions/query'
66
import { getEventsFromInput, createCallable, getDisplayName } from './utils'
7+
import { v3ErrorMessage } from './constants'
78

89
/**
910
* @name createFirebaseConnect
@@ -39,6 +40,11 @@ export const createFirebaseConnect = (storeKey = 'store') => (
3940
store = this.context[storeKey]
4041

4142
componentWillMount() {
43+
// Throw if using with react-redux@^6
44+
if (!this.context || !this.context[storeKey]) {
45+
// Use react-redux-firebase@^3 for react-redux@^6 support. More info available in the migration guide: http://bit.ly/2SRNdiO'
46+
throw new Error(v3ErrorMessage)
47+
}
4248
const { firebase, dispatch } = this.store
4349

4450
// Allow function to be passed

src/firestoreConnect.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
33
import { isEqual, some, filter } from 'lodash'
44
import hoistStatics from 'hoist-non-react-statics'
55
import { createCallable, wrapDisplayName } from './utils'
6+
import { v3ErrorMessage } from './constants'
67

78
/**
89
* @name createFirestoreConnect
@@ -40,6 +41,11 @@ export const createFirestoreConnect = (storeKey = 'store') => (
4041
}
4142

4243
componentWillMount() {
44+
// Throw if using with react-redux@^6
45+
if (!this.context || !this.context[storeKey]) {
46+
// Use react-redux-firebase@^3 for react-redux@^6 support. More info available in the migration guide: http://bit.ly/2SRNdiO'
47+
throw new Error(v3ErrorMessage)
48+
}
4349
const { firestore } = this.store
4450
if (this.firestoreIsEnabled) {
4551
// Allow function to be passed

src/withFirebase.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import hoistStatics from 'hoist-non-react-statics'
44
import { wrapDisplayName } from './utils'
5+
import { v3ErrorMessage } from './constants'
56

67
/**
78
* @name createWithFirebase
@@ -35,6 +36,11 @@ export const createWithFirebase = (storeKey = 'store') => WrappedComponent => {
3536
store = this.context[storeKey]
3637

3738
render() {
39+
// Throw if using with react-redux@^6
40+
if (!this.context || !this.context[storeKey]) {
41+
// Use react-redux-firebase@^3 for react-redux@^6 support. More info available in the migration guide: http://bit.ly/2SRNdiO'
42+
throw new Error(v3ErrorMessage)
43+
}
3844
return (
3945
<WrappedComponent
4046
{...this.props}

src/withFirestore.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import hoistStatics from 'hoist-non-react-statics'
44
import { wrapDisplayName } from './utils'
5+
import { v3ErrorMessage } from './constants'
56

67
/**
78
* @name createWithFirestore
@@ -34,6 +35,11 @@ export const createWithFirestore = (storeKey = 'store') => WrappedComponent => {
3435
store = this.context[storeKey]
3536

3637
render() {
38+
// Throw if using with react-redux@^6
39+
if (!this.context || !this.context[storeKey]) {
40+
// Use react-redux-firebase@^3 for react-redux@^6 support. More info available in the migration guide: http://bit.ly/2SRNdiO'
41+
throw new Error(v3ErrorMessage)
42+
}
3743
return (
3844
<WrappedComponent
3945
{...this.props}

0 commit comments

Comments
 (0)