Tell us what’s happening:
The Code was run successfully, the program did like it supposed to be, the state of message has move to Redux store using connection, but the why it’s still didn’t pass the point 7, 8 ,and 9. the point 7 I think was done right, also with 8 and 9 where I’ve been move the state to Redux store, and the message also right by referencing to redux store instead of component state
Your code so far
// Redux code (should be correct)
const ADD = 'ADD';
const addMessage = (message) => {
return {
type: ADD,
message
};
};
const messageReducer = (state = [], action) => {
switch (action.type) {
case ADD:
return [...state, action.message];
default:
return state;
}
};
const store = Redux.createStore(messageReducer);
// React code
const Provider = ReactRedux.Provider;
const connect = ReactRedux.connect;
class Presentational extends React.Component {
constructor(props) {
super(props);
this.state = {
input: ''
};
this.handleChange = this.handleChange.bind(this);
this.submitMessage = this.submitMessage.bind(this);
}
handleChange(event) {
this.setState({
input: event.target.value
});
}
submitMessage() {
this.props.submitNewMessage(this.state.input);
this.setState({
input: ''
});
}
render() {
return (
<div>
<h2>Type in a new Message:</h2>
<input
value={this.state.input}
onChange={this.handleChange}
/><br/>
<button onClick={this.submitMessage}>Submit</button>
<ul>
{this.props.messages.map((message, idx) => (
<li key={idx}>{message}</li>
))}
</ul>
</div>
);
}
}
const mapStateToProps = (state) => {
return { messages: state };
};
const mapDispatchToProps = (dispatch) => {
return {
submitNewMessage: (message) => {
dispatch(addMessage(message));
}
};
};
const Container = connect(mapStateToProps, mapDispatchToProps)(Presentational);
class AppWrapper extends React.Component {
render() {
return (
<Provider store={store}>
<Container />
</Provider>
);
}
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0
Challenge Information:
React and Redux - Extract Local State into Redux