Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs(connect): Expand on argument documentation for firebaseConnect
The existing docs didn't make it clear that you could have paths that
depended on props. I expanded on the argument documentation and added an
example.
  • Loading branch information
JustinTulloss committed Jun 10, 2017
commit b670882d03fd76f97c7c1fa59cc0b8a6ad650a9d
17 changes: 16 additions & 1 deletion src/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getEventsFromInput, createCallable } from './utils'
* @extends React.Component
* @description Higher Order Component that automatically listens/unListens
* to provided firebase paths using React's Lifecycle hooks.
* @param {Array} watchArray - Array of objects or strings for paths to sync from Firebase
* @param {Array} watchArray - Array of objects or strings for paths to sync from Firebase. Can also be a function that returns the array. The function is passed the current props and the firebase object.
* @return {Function} - that accepts a component to wrap and returns the wrapped component
* @example <caption>Basic</caption>
* // this.props.firebase set on App component as firebase object with helpers
Expand All @@ -30,6 +30,21 @@ import { getEventsFromInput, createCallable } from './utils'
* profile: pathToJS(firebase, 'profile'), // pass profile data as this.props.profile
* auth: pathToJS(firebase, 'auth') // pass auth data as this.props.auth
* }))(fbWrapped)
* @example <caption>Data that depends on props</caption>
* import { connect } from 'react-redux'
* import { firebaseConnect, dataToJS } from 'react-redux-firebase'
*
* // sync /todos from firebase into redux
* const fbWrapped = firebaseConnect((props, firebase) => ([
* `todos/${firebase.database().currentUser.uid}/${props.type}`
* ])(App)
*
* // pass todos list for the specified type of todos from redux as `this.props.todosList`
* export default connect(({ firebase, type }) => ({
* todosList: dataToJS(firebase, `data/todos/${firebase.getIn(['auth', 'uid'])}/${type}`),
* profile: pathToJS(firebase, 'profile'), // pass profile data as this.props.profile
* auth: pathToJS(firebase, 'auth') // pass auth data as this.props.auth
* }))(fbWrapped)
*/
export default (dataOrFn = []) => WrappedComponent => {
class FirebaseConnect extends Component {
Expand Down