0

I'm trying to query a database with this structure.

enter image description here

This is my query so far:

componentDidMount() {
    const itemsRef = firebase.database().ref('works');
    itemsRef.on('value', (snapshot) => {
        console.log('snap', snapshot);
        console.log('val', snapshot.val());
        let items = snapshot.val();
        let newState = [];
        console.log('tu ', items);
        for (let item in items) {
            console.log(item);
            newState.push({
                id: item,
                title: items[item].title,
                user: items[item].user
            });
        }
        this.setState({
            items: newState
        });
    });
}

I know it's wrong, because it returns null. How do I make it correct? I was following a tutorial earlier, but this is a little more complex then a todo list. I want to list the works.

This is the console response:

snap Object { node_: {…}, ref_: {…}, index_: {} } questions.js:17
val null questions.js:18
tu  null questions.js:21 
0

1 Answer 1

2

Change this:

const itemsRef = firebase.database().ref('works');

into this:

const itemsRef = firebase.database().ref('Works');

since you have works as capital letter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.