1
votes

In my react app i fetch a list of items from Firebase to show in a listview.

    this.fb = new Firebase(rootUrl + 'items/');
    this.bindAsObject(this.fb, 'items');
    this.fb.on('value', this.handleDataLoaded);

Each item has a value of a uid for a user who posted it.

I use authData.uid in the app to get the logged in users uid.

How can i go about filtering the list to show only the projects by that user?

1

1 Answers

1
votes

Have you tried using a snapshot to filter lists? It is way more efficient...

Here's how to use one:

var ref = new Firebase("https://YOUR-URL.firebaseio.com/");
    ref.orderByChild("location").equalTo("United States").on("child_added", function(snapshot) {
      document.write(snapshot.key());
    console.log(snapshot.key());
    });

You've asked: "How can i go about filtering the list to show only the projects by that user?"

The above is simply an example. In your case, replace location with project, or whatever parameter type you have stored in your database (at https://YOUR-URL.firebaseio.com/), and United States will be replaced by the user name, id, or whatever parameter value you have stored for that user to be identified in code.

A basic Firebase query starts with one of our orderBy functions: orderByChild(), orderByKey(), or orderByPriority(). You can then combine these with five other methods to conduct complex queries: limitToFirst(), limitToLast(), startAt(), endAt(), and equalTo(). Figure out which function to use.

See here for more details on how to use a snapshot: firebase.com/blog/2014-11-04-firebase-realtime-queries.html