Javascript Reactjs不呈现表中的数据

Javascript Reactjs不呈现表中的数据,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,从firestore获取数据并尝试使用reactJS在表中呈现,我无法呈现它。有人知道我是否有错误吗 这是我的代码: state = { items:[] }; componentDidMount(){ db.collection('items').get().then((snapShot) => { snapShot.docs.map( doc => { this.state.items.push({ id: doc.id,

从firestore获取数据并尝试使用reactJS在表中呈现,我无法呈现它。有人知道我是否有错误吗

这是我的代码:

state = {
    items:[]
};

componentDidMount(){
    db.collection('items').get().then((snapShot) => {
        snapShot.docs.map( doc => {
           this.state.items.push({ id: doc.id, data: doc.data()});
        })
   }, error => {
       console.log(error)
   }); 
};
表格

render() {
    const { items, inputValue } = this.state;
    console.log(items)
    return (
        <React.Fragment>
            <Table hover className="text-center">
                <thead>
                <tr>
                    <th>Name</th>
                    <th>Edit</th>
                    <th>Delete</th>
                </tr>
                </thead>
                <tbody>  
                    { items && items !== undefined ? items.map((item, key) => (
                        <tr><td>{item.data.item}</td></tr>
                     )): null }
                </tbody>
             </Table>
        </React.Fragment>
    )
  }
使用map我无法访问数据

你能帮帮我吗?谢谢您在componentDidMount()中设置您的状态

componentDidMount(){
    db.collection('items').get().then((snapShot) => {
       this.setState({
       items:snapShot.docs.map( doc => {
           return { id: doc.id, data: doc.data()}               
        });
       });
   }, error => {
       console.log(error)
   }); 
};
在componentDidMount()中,必须设置状态

componentDidMount(){
    db.collection('items').get().then((snapShot) => {
       this.setState({
       items:snapShot.docs.map( doc => {
           return { id: doc.id, data: doc.data()}               
        });
       });
   }, error => {
       console.log(error)
   }); 
};

this.state.items.push
不直接修改state对象。使用
setState
方法。@YuryTarabanko我不知道我是怎么忘记的!谢谢你
this.state.items.push不直接修改state对象。使用
setState
方法。@YuryTarabanko我不知道我是怎么忘记的!非常感谢。