SyncState

re-base's syncState() method makes it easy to bind Firebase and React. That is, when a change occurs to either the Firebase database or the React component, the change is reflected on the other.

Using syncState() in a React component is easy. Let's use the List.js from the React chapter as an example.

At the top of the file, import base from the previous section:

import base from './rebase';

Then, in List.js's componentDidMount() method, do the following to sync the List component's state with Firebase:

componentDidMount() {
  this.ref = base.syncState('list', {
    context: this,
    state: 'list',
    asArray: true
  });
}

That's it! Your list is now synced with Firebase.

results matching ""

    No results matching ""