Skip to content

Commit 47e41da

Browse files
author
Scott Prue
committed
fix(firebaseConnect): remove dispatch from reserved props list - #700
* fix(firestoreConnect): add error for passing of reserved props "firebase" and "firestore" when using firestoreConnect
1 parent 5d44df6 commit 47e41da

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

src/firebaseConnect.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { watchEvents, unWatchEvents } from './actions/query'
66
import { getEventsFromInput, createCallable, wrapDisplayName } from './utils'
77
import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
88

9-
// Reserved props that should not be passed into a firebaseConnect wrapped
10-
// component. Will throw an error if they are.
11-
const RESERVED_PROPS = ['firebase', 'dispatch']
12-
139
/**
1410
* Function that creates a Higher Order Component which
1511
* automatically listens/unListens to provided firebase paths using
@@ -102,23 +98,21 @@ export const createFirebaseConnect = (storeKey = 'store') => (
10298
// Check that reserved props are not supplied to a FirebaseConnected
10399
// component and if they are, throw an error so the developer can rectify
104100
// this issue.
105-
const clashes = Object.keys(props).filter(k => RESERVED_PROPS.includes(k))
101+
const clashes = Object.keys(props).includes('firebase')
106102

107103
if (clashes.length > 0) {
108104
throw new Error(
109-
`Supplied prop/s "${clashes.join(
110-
'", "'
111-
)}" are reserved for internal firebaseConnect() usage.`
105+
`Supplied prop "firebase" is reserved for internal firebaseConnect() usage.`
112106
)
113107
}
114108

115109
return (
116110
<ReactReduxFirebaseContext.Consumer>
117111
{_internalFirebase => (
118112
<HoistedComp
119-
firebase={_internalFirebase}
120-
dispatch={_internalFirebase.dispatch}
121113
{...props}
114+
dispatch={_internalFirebase.dispatch}
115+
firebase={_internalFirebase}
122116
/>
123117
)}
124118
</ReactReduxFirebaseContext.Consumer>

src/firestoreConnect.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { createCallable, wrapDisplayName } from './utils'
66
import ReduxFirestoreContext from './ReduxFirestoreContext'
77
import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
88

9+
// Reserved props that should not be passed into a firebaseConnect wrapped
10+
// component. Will throw an error if they are.
11+
const RESERVED_PROPS = ['firebase', 'firestore']
12+
913
/**
1014
* Function that creates a Higher Order Component which
1115
* automatically listens/unListens to provided firebase paths using
@@ -94,22 +98,38 @@ export const createFirestoreConnect = (storeKey = 'store') => (
9498

9599
const HoistedComp = hoistStatics(FirestoreConnectWrapped, WrappedComponent)
96100

97-
const FirestoreConnect = props => (
98-
<ReactReduxFirebaseContext.Consumer>
99-
{firebase => (
100-
<ReduxFirestoreContext.Consumer>
101-
{firestore => (
102-
<HoistedComp
103-
firestore={firestore}
104-
firebase={firebase}
105-
dispatch={firebase.dispatch}
106-
{...props}
107-
/>
108-
)}
109-
</ReduxFirestoreContext.Consumer>
110-
)}
111-
</ReactReduxFirebaseContext.Consumer>
112-
)
101+
const FirestoreConnect = props => {
102+
// Check that reserved props are not supplied to a FirebaseConnected
103+
// component and if they are, throw an error so the developer can rectify
104+
// this issue.
105+
const clashes = Object.keys(props).filter(k => RESERVED_PROPS.includes(k))
106+
107+
if (clashes.length > 0) {
108+
const moreThanOne = clashes.length > 1
109+
throw new Error(
110+
`Supplied prop${moreThanOne ? 's' : ''} "${clashes.join('", "')}" ${
111+
moreThanOne ? 'are' : 'is'
112+
} reserved for internal firestoreConnect() usage.`
113+
)
114+
}
115+
116+
return (
117+
<ReactReduxFirebaseContext.Consumer>
118+
{firebase => (
119+
<ReduxFirestoreContext.Consumer>
120+
{firestore => (
121+
<HoistedComp
122+
{...props}
123+
dispatch={firebase.dispatch}
124+
firestore={firestore}
125+
firebase={firebase}
126+
/>
127+
)}
128+
</ReduxFirestoreContext.Consumer>
129+
)}
130+
</ReactReduxFirebaseContext.Consumer>
131+
)
132+
}
113133

114134
FirestoreConnect.displayName = wrapDisplayName(
115135
WrappedComponent,

0 commit comments

Comments
 (0)