Commented full solution (#35620)
* Include a default case for messageReducer * Commented full solution
This commit is contained in:
committed by
Randell Dawson
parent
64efcac199
commit
2565d4c44a
@ -53,6 +53,8 @@ const connect = ReactRedux.connect;
|
||||
class Presentational extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
// Remove property 'messages' from Presentational's local state
|
||||
this.state = {
|
||||
input: ''
|
||||
}
|
||||
@ -65,11 +67,13 @@ class Presentational extends React.Component {
|
||||
});
|
||||
}
|
||||
submitMessage() {
|
||||
this.props.submitNewMessage(this.state.input);
|
||||
this.setState({
|
||||
input: ''
|
||||
});
|
||||
|
||||
|
||||
// Call 'submitNewMessage', which has been mapped to Presentational's props, with a new message;
|
||||
// meanwhile, remove the 'messages' property from the object returned by this.setState().
|
||||
this.props.submitNewMessage(this.state.input);
|
||||
this.setState({
|
||||
input: ''
|
||||
});
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
@ -80,6 +84,9 @@ class Presentational extends React.Component {
|
||||
onChange={this.handleChange}/><br/>
|
||||
<button onClick={this.submitMessage}>Submit</button>
|
||||
<ul>
|
||||
{/* The messages state is mapped to Presentational's props; therefore, when rendering,
|
||||
you should access the messages state through props, instead of Presentational's
|
||||
local state. */}
|
||||
{this.props.messages.map( (message, idx) => {
|
||||
return (
|
||||
<li key={idx}>{message}</li>
|
||||
|
Reference in New Issue
Block a user