Tell us what’s happening:
Can someone tell whats wrong with this code…
giving error as “Cannot call a class as a function”
Your code so far
// Redux Code:
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:
class DisplayMessages extends React.Component {
constructor(props) {
super(props);
this.state = {
input: '',
messages: []
}
this.handleChange = this.handleChange.bind(this);
this.submitMessage = this.submitMessage.bind(this);
}
handleChange(event) {
this.setState({
input: event.target.value
});
}
submitMessage() {
this.setState({
messages: [...this.state.messages, this.state.input],
input:""
});
}
render() {
const msgs = this.state.messages.map(x=><li>{x}</li>);
return (
<div>
<h2>Type in a new Message:</h2>
<input
type = "text"
value={this.state.input}
onChange={this.handleChange}/><br/>
<button onClick={this.submitMessage}>Submit</button>
<ul>
{msgs}
</ul>
</div>
);
}
};
const Provider = ReactRedux.Provider(store);
class AppWrapper extends React.Component {
// render the Provider here
render(){
return(
<Provider store={store}>
<DisplayMessages/>
</Provider>
)
}
// change code above this line
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/use-provider-to-connect-redux-to-react/