Use Provider to Connect Redux to React - stuck

Use Provider to Connect Redux to React - stuck
0

#1

Tell us what’s happening:
I am lost.

Minified React error #152; visit https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=AppWrapper for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

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() {
    const currentMessage = this.state.input;
    this.setState({
      input: '',
      messages: this.state.messages.concat(currentMessage)
    });
  }
  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.state.messages.map( (message, idx) => {
              return (
                 <li key={idx}>{message}</li>
              )
            })
          }
        </ul>
      </div>
    );
  }
};

const Provider = ReactRedux.Provider;


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) Ubuntu Chromium/67.0.3396.99 Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/use-provider-to-connect-redux-to-react


#2

The problem is your return statement. In JavaScript if you only write return on a single line, it will return undefined.

function wrongReturn() {
  return 
  (3);
}
wrongReturn(); // returns undefined

function rightReturn() {
  return (
    3
  );
}
rightReturn(); // returns 3

Move the opening parentheses of the next line to be on the same line (after return keyword) and you are good to go.


#3

Well I’ll be blowed! :hushed: