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 {
|
class Presentational extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
// Remove property 'messages' from Presentational's local state
|
||||||
this.state = {
|
this.state = {
|
||||||
input: ''
|
input: ''
|
||||||
}
|
}
|
||||||
@ -65,11 +67,13 @@ class Presentational extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
submitMessage() {
|
submitMessage() {
|
||||||
this.props.submitNewMessage(this.state.input);
|
|
||||||
this.setState({
|
// Call 'submitNewMessage', which has been mapped to Presentational's props, with a new message;
|
||||||
input: ''
|
// meanwhile, remove the 'messages' property from the object returned by this.setState().
|
||||||
});
|
this.props.submitNewMessage(this.state.input);
|
||||||
|
this.setState({
|
||||||
|
input: ''
|
||||||
|
});
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -80,6 +84,9 @@ class Presentational extends React.Component {
|
|||||||
onChange={this.handleChange}/><br/>
|
onChange={this.handleChange}/><br/>
|
||||||
<button onClick={this.submitMessage}>Submit</button>
|
<button onClick={this.submitMessage}>Submit</button>
|
||||||
<ul>
|
<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) => {
|
{this.props.messages.map( (message, idx) => {
|
||||||
return (
|
return (
|
||||||
<li key={idx}>{message}</li>
|
<li key={idx}>{message}</li>
|
||||||
|
Reference in New Issue
Block a user