Q:

Reactjs componentDidMount with dataread when no values

I have a reactjs application talking to Mogodb-Atlas. 
when I am reading some times there is no data in the db and it is crashing. 
As I have to show thhe data in the UI (in render) I am doing the reading in the componentdidmont
componentDidMount = async (event) => {
        const { theId } = this.props
        const { mongodb } = this.props;
        await mongodb.db("MasterDB")
            .collection("ReadyTable")
            .find({"theId":Id,"Flag":"Ready"})
            .asArray()
            .then(ReadyTable => {
                this.setState({ ReadyTable });
                this.setState({ toprocessID: ReadyTable[0].toprocessID });
                }
                });

This code works if there is entry in that table with Ready. 
sometimes that table is not updated and than this crashes. 
is there a way I can make sure it does not crash. 
As there is no data it crashesas I am assigning that data

A:

You need to add a condition to render function before using ReadyTable array.  It maybe helps you.  Here is an example of the same. 
render() {
  const { ReadyTable } = this.state;
  return(
     ReadyTable.length > 0 && 
      // other stuff that you want show
  )
}

