Creating a message

As in our LoginContainer, we need to store the value of our textarea in state as it changes.

We used the state of the LoginContainer to store that value. Let's do the same with ChatContainer.

You may be wondering, after the preceding discussion: why don't we just keep all our state in App? Some will argue for that approach, to keep everything in one place; however, this will bloat our App component and require us to pass multiple props between components. It's better to keep state as high as necessary, and no higher; the new message in the chat input will only be relevant to App when it's done and submitted, not before that.

Let's get that set up.

Add this to the ChatContainer.js:

state = { newMessage: '' };

Also, add a ...

Get Progressive Web Apps with React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.