How to dispatch method from this.props REACT/REDUX

Tell us what’s happening:
in the task it asks

Next, modify the submitMessage() method so that it dispatches submitNewMessage() from this.props , and pass in the current message input from local state as an argument.

This is where I am having issues , can you refer me to documentation or previous lessson that I should do again in order to understand it?

**Your code so far**
      
```jsx

// Redux:
const ADD = 'ADD';

const addMessage = (message) => {
return {
  type: ADD,
  message: message
}
};

const messageReducer = (state = [], action) => {
switch (action.type) {
  case ADD:
    return [
      ...state,
      action.message
    ];
  default:
    return state;
}
};

const store = Redux.createStore(messageReducer);

// React:
const Provider = ReactRedux.Provider;
const connect = ReactRedux.connect;

// Change code below this line
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.dispatch(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) => {
            return (
               <li key={idx}>{message}</li>
            )
          })
        }
      </ul>
    </div>
  );
}
};
// Change code above this line

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Extract Local State into Redux

Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/react-and-redux/extract-local-state-into-redux

solved it myself, no worries

1 Like