React Native: Why are constructor and componentDidMount not called?


#1

Hey,
I’m having a chat view with some messages in it. I’m generating my message components like this in my chat view:

class Chat extends Component {
 
       //props.messages are loaded via container
       getMessages() {
        if(this.props.messages) {
            return this.props.messages.map(message => (<Message doc={message}/>));
        }

     render() {
     return <View>{this.getMessages()}</View>
      }

    }

}

Messages are defined like this:

class Message extends Component {
    
     constructor(props) {
     super(props);
     console.log("Fired constructor");
      }

    componentDidMount() {
        console.log("Fired cDm");
    }

   genMessage() {
    return <Text>{this.props.doc.messageText}</Text>
   }
   render() {
    return this.genMessage();
    }

}

Now this is the behavior:

If I open the chat view and load all messages for the first time, constructor and componentDidMount are fired for each message. But if I add dynamically a message, none of them is fired - but the message is displayed. Can somebody tell me why both of them aren’t called, even if the new “object” is displayed?