React + Firebase database componentDidMount and snapshot not working











up vote
0
down vote

favorite












I am trying to get .on('value') to fire so I can retrieve data but something is not working correctly. 'Mounted' logs fine, but 'test' does not. Can somebody please explain what I am probably misunderstanding? Additionally, I would like to update the state as shown in the commented out code.



Thank you for your help!



    import React, { Component } from 'react'
import './Creature.css'
import Emblem from '../../../img/emblem_macabre.png'
import Macabre from '../../../img/macabre.jpg'
import * as firebase from 'firebase';

class Creature extends Component {

constructor() {
super()
this.state = {
name: '',
cultId: ''
}
}

componentDidMount() {
console.log('mounted')
const creatureCards = firebase.database().ref().child('creatureCards')
console.log(creatureCards)
creatureCards.on('value', snap => {
console.log('test')
})

// var name = snap.child('name').getValue()
// var cultId = snap.child('cultId').getValue()

// this.setState({
// name: name,
// cultId: cultId
// })
}

render() {
return(
<div className="creatureCard">
<span className="creatureName">{this.state.name}</span>
<span className="creatureArt"><img src={Macabre} alt=""/></span>
<ul className="creatureAttributes">
<li className="creatureAttribute">R</li>
<li className="creatureAttribute">D</li>
<li className="creatureAttribute">I</li>
<li className="creatureAttribute">H</li>
</ul>
<span className="creatureDescription">
<p>Card descriptions and abilities. This section defines the card and its roll in the game.</p>
</span>
<div className="emblem">
<img src={Emblem} alt=""/>
</div>
</div>
)
}
}

export default Creature









share|improve this question
























  • Does your user have permission to read creatureCards? You can easily detect this by adding an error callback: creatureCards.on('value', snap => { console.log('test') }, error => { console.error(error) } )
    – Frank van Puffelen
    Nov 3 at 3:28










  • Yes. I copied and pasted that in and it did not show an error. Any other thoughts?
    – gumball
    Nov 3 at 3:52










  • Update: It actually did throw an error this time. My database and storage are both set to public though. I will reasearch this. Can you provide a possible solution, please?
    – gumball
    Nov 10 at 20:57















up vote
0
down vote

favorite












I am trying to get .on('value') to fire so I can retrieve data but something is not working correctly. 'Mounted' logs fine, but 'test' does not. Can somebody please explain what I am probably misunderstanding? Additionally, I would like to update the state as shown in the commented out code.



Thank you for your help!



    import React, { Component } from 'react'
import './Creature.css'
import Emblem from '../../../img/emblem_macabre.png'
import Macabre from '../../../img/macabre.jpg'
import * as firebase from 'firebase';

class Creature extends Component {

constructor() {
super()
this.state = {
name: '',
cultId: ''
}
}

componentDidMount() {
console.log('mounted')
const creatureCards = firebase.database().ref().child('creatureCards')
console.log(creatureCards)
creatureCards.on('value', snap => {
console.log('test')
})

// var name = snap.child('name').getValue()
// var cultId = snap.child('cultId').getValue()

// this.setState({
// name: name,
// cultId: cultId
// })
}

render() {
return(
<div className="creatureCard">
<span className="creatureName">{this.state.name}</span>
<span className="creatureArt"><img src={Macabre} alt=""/></span>
<ul className="creatureAttributes">
<li className="creatureAttribute">R</li>
<li className="creatureAttribute">D</li>
<li className="creatureAttribute">I</li>
<li className="creatureAttribute">H</li>
</ul>
<span className="creatureDescription">
<p>Card descriptions and abilities. This section defines the card and its roll in the game.</p>
</span>
<div className="emblem">
<img src={Emblem} alt=""/>
</div>
</div>
)
}
}

export default Creature









share|improve this question
























  • Does your user have permission to read creatureCards? You can easily detect this by adding an error callback: creatureCards.on('value', snap => { console.log('test') }, error => { console.error(error) } )
    – Frank van Puffelen
    Nov 3 at 3:28










  • Yes. I copied and pasted that in and it did not show an error. Any other thoughts?
    – gumball
    Nov 3 at 3:52










  • Update: It actually did throw an error this time. My database and storage are both set to public though. I will reasearch this. Can you provide a possible solution, please?
    – gumball
    Nov 10 at 20:57













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to get .on('value') to fire so I can retrieve data but something is not working correctly. 'Mounted' logs fine, but 'test' does not. Can somebody please explain what I am probably misunderstanding? Additionally, I would like to update the state as shown in the commented out code.



Thank you for your help!



    import React, { Component } from 'react'
import './Creature.css'
import Emblem from '../../../img/emblem_macabre.png'
import Macabre from '../../../img/macabre.jpg'
import * as firebase from 'firebase';

class Creature extends Component {

constructor() {
super()
this.state = {
name: '',
cultId: ''
}
}

componentDidMount() {
console.log('mounted')
const creatureCards = firebase.database().ref().child('creatureCards')
console.log(creatureCards)
creatureCards.on('value', snap => {
console.log('test')
})

// var name = snap.child('name').getValue()
// var cultId = snap.child('cultId').getValue()

// this.setState({
// name: name,
// cultId: cultId
// })
}

render() {
return(
<div className="creatureCard">
<span className="creatureName">{this.state.name}</span>
<span className="creatureArt"><img src={Macabre} alt=""/></span>
<ul className="creatureAttributes">
<li className="creatureAttribute">R</li>
<li className="creatureAttribute">D</li>
<li className="creatureAttribute">I</li>
<li className="creatureAttribute">H</li>
</ul>
<span className="creatureDescription">
<p>Card descriptions and abilities. This section defines the card and its roll in the game.</p>
</span>
<div className="emblem">
<img src={Emblem} alt=""/>
</div>
</div>
)
}
}

export default Creature









share|improve this question















I am trying to get .on('value') to fire so I can retrieve data but something is not working correctly. 'Mounted' logs fine, but 'test' does not. Can somebody please explain what I am probably misunderstanding? Additionally, I would like to update the state as shown in the commented out code.



Thank you for your help!



    import React, { Component } from 'react'
import './Creature.css'
import Emblem from '../../../img/emblem_macabre.png'
import Macabre from '../../../img/macabre.jpg'
import * as firebase from 'firebase';

class Creature extends Component {

constructor() {
super()
this.state = {
name: '',
cultId: ''
}
}

componentDidMount() {
console.log('mounted')
const creatureCards = firebase.database().ref().child('creatureCards')
console.log(creatureCards)
creatureCards.on('value', snap => {
console.log('test')
})

// var name = snap.child('name').getValue()
// var cultId = snap.child('cultId').getValue()

// this.setState({
// name: name,
// cultId: cultId
// })
}

render() {
return(
<div className="creatureCard">
<span className="creatureName">{this.state.name}</span>
<span className="creatureArt"><img src={Macabre} alt=""/></span>
<ul className="creatureAttributes">
<li className="creatureAttribute">R</li>
<li className="creatureAttribute">D</li>
<li className="creatureAttribute">I</li>
<li className="creatureAttribute">H</li>
</ul>
<span className="creatureDescription">
<p>Card descriptions and abilities. This section defines the card and its roll in the game.</p>
</span>
<div className="emblem">
<img src={Emblem} alt=""/>
</div>
</div>
)
}
}

export default Creature






javascript reactjs firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 23:47

























asked Nov 3 at 3:26









gumball

113




113












  • Does your user have permission to read creatureCards? You can easily detect this by adding an error callback: creatureCards.on('value', snap => { console.log('test') }, error => { console.error(error) } )
    – Frank van Puffelen
    Nov 3 at 3:28










  • Yes. I copied and pasted that in and it did not show an error. Any other thoughts?
    – gumball
    Nov 3 at 3:52










  • Update: It actually did throw an error this time. My database and storage are both set to public though. I will reasearch this. Can you provide a possible solution, please?
    – gumball
    Nov 10 at 20:57


















  • Does your user have permission to read creatureCards? You can easily detect this by adding an error callback: creatureCards.on('value', snap => { console.log('test') }, error => { console.error(error) } )
    – Frank van Puffelen
    Nov 3 at 3:28










  • Yes. I copied and pasted that in and it did not show an error. Any other thoughts?
    – gumball
    Nov 3 at 3:52










  • Update: It actually did throw an error this time. My database and storage are both set to public though. I will reasearch this. Can you provide a possible solution, please?
    – gumball
    Nov 10 at 20:57
















Does your user have permission to read creatureCards? You can easily detect this by adding an error callback: creatureCards.on('value', snap => { console.log('test') }, error => { console.error(error) } )
– Frank van Puffelen
Nov 3 at 3:28




Does your user have permission to read creatureCards? You can easily detect this by adding an error callback: creatureCards.on('value', snap => { console.log('test') }, error => { console.error(error) } )
– Frank van Puffelen
Nov 3 at 3:28












Yes. I copied and pasted that in and it did not show an error. Any other thoughts?
– gumball
Nov 3 at 3:52




Yes. I copied and pasted that in and it did not show an error. Any other thoughts?
– gumball
Nov 3 at 3:52












Update: It actually did throw an error this time. My database and storage are both set to public though. I will reasearch this. Can you provide a possible solution, please?
– gumball
Nov 10 at 20:57




Update: It actually did throw an error this time. My database and storage are both set to public though. I will reasearch this. Can you provide a possible solution, please?
– gumball
Nov 10 at 20:57












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The problem was that at some point I switched to firestore but was still making calls to the database.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53128137%2freact-firebase-database-componentdidmount-and-snapshot-not-working%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    The problem was that at some point I switched to firestore but was still making calls to the database.






    share|improve this answer

























      up vote
      0
      down vote













      The problem was that at some point I switched to firestore but was still making calls to the database.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        The problem was that at some point I switched to firestore but was still making calls to the database.






        share|improve this answer












        The problem was that at some point I switched to firestore but was still making calls to the database.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 23:32









        gumball

        113




        113






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53128137%2freact-firebase-database-componentdidmount-and-snapshot-not-working%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation