@@ -5,46 +5,6 @@ import { wrapDisplayName } from './utils'
55import useFirebase from './useFirebase'
66import useFirestore from './useFirestore'
77
8- /**
9- * @name createWithFirestore
10- * @description Function that creates a Higher Order Component that
11- * which provides `firebase`, `firestore`, and `dispatch` to React Components.
12- *
13- * **WARNING!!** This is an advanced feature, and should only be used when
14- * needing to access a firebase instance created under a different store key.
15- * @param {String } [storeKey='store'] - Name of redux store which contains
16- * Firestore state (`state.firestore`)
17- * @return {Function } - Higher Order Component which accepts an array of
18- * watchers config and wraps a React Component
19- * @example <caption>Basic</caption>
20- * import { createWithFirestore } from 'react-redux-firebase'
21- *
22- * // create withFirestore that uses another redux store
23- * const withFirestore = createWithFirestore('anotherStore')
24- *
25- * // use the withFirestore to wrap a component
26- * export default withFirestore(SomeComponent)
27- */
28- export const createWithFirestore = ( storeKey = 'store' ) => WrappedComponent => {
29- const WithFirestore = function WithFirestore ( props ) {
30- const firebase = useFirebase ( )
31- const firestore = useFirestore ( )
32- return (
33- < WrappedComponent
34- firebase = { firebase }
35- dispatch = { get ( firebase , 'dispatch' ) }
36- firestore = { firestore }
37- { ...props }
38- />
39- )
40- }
41-
42- WithFirestore . displayName = wrapDisplayName ( WrappedComponent , 'withFirestore' )
43- WithFirestore . wrappedComponent = WrappedComponent
44-
45- return hoistStatics ( WithFirestore , WrappedComponent )
46- }
47-
488/**
499 * @name withFirestore
5010 * @extends React.Component
@@ -98,4 +58,22 @@ export const createWithFirestore = (storeKey = 'store') => WrappedComponent => {
9858 *
9959 * export default enhance(AddTodo)
10060 */
101- export default createWithFirestore ( )
61+ export default function withFirestore ( WrappedComponent ) {
62+ function WithFirestore ( props ) {
63+ const firebase = useFirebase ( )
64+ const firestore = useFirestore ( )
65+ return (
66+ < WrappedComponent
67+ firebase = { firebase }
68+ dispatch = { get ( firebase , 'dispatch' ) }
69+ firestore = { firestore }
70+ { ...props }
71+ />
72+ )
73+ }
74+
75+ WithFirestore . displayName = wrapDisplayName ( WrappedComponent , 'withFirestore' )
76+ WithFirestore . wrappedComponent = WrappedComponent
77+
78+ return hoistStatics ( WithFirestore , WrappedComponent )
79+ }
0 commit comments