react-firebase-hoc
React Higher Order Components for Firebase. Compatible with React and React Native.
Requirements
How to use
-
Install the package
npm install react-firebase-hoc -
Use them on your component
;;const firebaseConfig = ...;const firebaseApp = firebase;/*** later after component declaration...* 1st param is the firebaseApp instance* 2nd param is the namespace for the fetched data* 3rd param is the callback, (db, props, state)*/const MyComponentWithData =MyComponent// or you can use it as decorator too@Component ... -
You'll get the injected props on your component
// users is the namespace specified on the first param of HOCconsole // true/falseconsole // null/objectconsole // null/object
Callback parameters
You also have access to the props and state on the callback HOC
@
Tips
You can re-wrap the HOC if you always use one firebaseApp instance, for example:
;; const firebaseConfig = ...;const firebaseApp = firebase; { return ;}
License
MIT