2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 5a24c314108439a4d4036144
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Use Provider to Connect Redux to React
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 6
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 301435
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: use-provider-to-connect-redux-to-react
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								In the last challenge, you created a Redux store to handle the messages array and created an action for adding new messages. The next step is to provide React access to the Redux store and the actions it needs to dispatch updates. React Redux provides its `react-redux`  package to help accomplish these tasks.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								React Redux provides a small API with two key features: `Provider`  and `connect` . Another challenge covers `connect` . The `Provider`  is a wrapper component from React Redux that wraps your React app. This wrapper then allows you to access the Redux `store`  and `dispatch`  functions throughout your component tree. `Provider`  takes two props, the Redux store and the child components of your app. Defining the `Provider`  for an App component might look like this:
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 05:01:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```jsx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< Provider  store = {store} >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < App / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / Provider >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The code editor now shows all your Redux and React code from the past several challenges. It includes the Redux store, actions, and the `DisplayMessages`  component. The only new piece is the `AppWrapper`  component at the bottom. Use this top level component to render the `Provider`  from `ReactRedux` , and pass the Redux store as a prop. Then render the `DisplayMessages`  component as a child. Once you are finished, you should see your React component rendered to the page.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								**Note:** React Redux is available as a global variable here, so you can access the Provider with dot notation. The code in the editor takes advantage of this and sets it to a constant `Provider`  for you to use in the `AppWrapper`  render method.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `AppWrapper`  should render.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return mockedComponent.find('AppWrapper').length === 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The `Provider`  wrapper component should have a prop of `store`  passed to it, equal to the Redux store.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(getUserInput) =>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return __helpers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        .removeWhiteSpace(getUserInput('index'))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        .includes('< Providerstore = { store } > ');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`DisplayMessages`  should render as a child of `AppWrapper` . 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      mockedComponent.find('AppWrapper').find('DisplayMessages').length === 1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-25 09:19:24 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `DisplayMessages`  component should render an `h2` , `input` , `button` , and `ul`  element.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      mockedComponent.find('div').length === 1 & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      mockedComponent.find('h2').length === 1 & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      mockedComponent.find('button').length === 1 & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      mockedComponent.find('ul').length === 1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --seed--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## --after-user-code--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```jsx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ReactDOM.render(< AppWrapper  / > , document.getElementById('root'))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## --seed-contents--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```jsx
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Redux:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								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);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// React:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class DisplayMessages extends React.Component {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  constructor(props) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    super(props);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.state = {
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      input: '',
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      messages: []
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.handleChange = this.handleChange.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.submitMessage = this.submitMessage.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  handleChange(event) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.setState({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      input: event.target.value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
									
										
										
										
											2020-08-11 22:42:27 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  submitMessage() {  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.setState((state) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      const currentMessage = state.input;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        input: '',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        messages: state.messages.concat(currentMessage)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  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 {
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // Render the Provider below this line
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // Change code above this line
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-13 18:58:50 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```jsx
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Redux:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								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);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// React:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class DisplayMessages extends React.Component {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  constructor(props) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    super(props);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.state = {
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      input: '',
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      messages: []
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 this.handleChange = this.handleChange.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 this.submitMessage = this.submitMessage.bind(this);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  handleChange(event) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.setState({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      input: event.target.value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  submitMessage() {
							 
						 
					
						
							
								
									
										
										
										
											2020-08-11 22:42:27 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.setState((state) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      const currentMessage = state.input;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        input: '',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        messages: state.messages.concat(currentMessage)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      };  
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  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 {
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // Change code below this line
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  render() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < Provider  store  =  {store} > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < DisplayMessages / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < / Provider > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // Change code above this line
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```