score:0

class Apps extends React.Component {

constructor(props) {
    super(props)
    this.state = {
        names: [],
    }
}

componentDidMount() {

    let array = [];
    db.collection("users").get()
        .then((snapshot) => {

            snapshot.forEach((doc) => {

                const user = {
                    name: doc.data().name,
                    weight: doc.data().weight,
                    id: doc.id
                }
                array.push(user)
            })
        })
        .then(() => {
            this.setState({
                names : array
            })
        })
}

render() {
    ///this show the data in names array of state
    console.log(this.state.names)
    //// this show undefind (its having data)
    console.log(this.state.names[0])
    return (
        ///but while rendering its not showing anything
        <div>{this.state.names.map((name) => (
            <h1>weight is {name.weight} </h1>
        )
        )}</div>
    )
}
}

export default Apps;

score:1

this.setGlobal(names: names.push(user))

Related Query

More Query from same tag