2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								id: 5a24c314108439a4d403618a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								title: Use Array.map() to Dynamically Render Elements
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								challengeType: 6
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								forumTopicId: 301417
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								dashedName: use-array-map-to-dynamically-render-elements
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# --description--
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Conditional rendering is useful, but you may need your components to render an unknown number of elements. Often in reactive programming, a programmer has no way to know what the state of an application is until runtime, because so much depends on a user's interaction with that program. Programmers need to write their code to correctly handle that unknown state ahead of time. Using `Array.map()`  in React illustrates this concept.
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-27 15:45:37 -01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								For example, you create a simple "To Do List" app. As the programmer, you have no way of knowing how many items a user might have on their list. You need to set up your component to dynamically render the correct number of list elements long before someone using the program decides that today is laundry day.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# --instructions--
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The code editor has most of the `MyToDoList`  component set up. Some of this code should look familiar if you completed the controlled form challenge. You'll notice a `textarea`  and a `button` , along with a couple of methods that track their states, but nothing is rendered to the page yet.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Inside the `constructor` , create a `this.state`  object and define two states: `userInput`  should be initialized as an empty string, and `toDoList`  should be initialized as an empty array. Next, delete the comment in the `render()`  method next to the `items`  variable. In its place, map over the `toDoList`  array stored in the component's internal state and dynamically render a `li`  for each item. Try entering the string `eat, code, sleep, repeat`  into the `textarea` , then click the button and see what happens.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								**Note:** You may know that all sibling child elements created by a mapping operation like this do need to be supplied with a unique `key`  attribute. Don't worry, this is the topic of the next challenge.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# --hints--
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The MyToDoList component should exist and render to the page.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return mockedComponent.find('MyToDoList').length === 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The first child of `MyToDoList`  should be a `textarea`  element.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mockedComponent.find('MyToDoList').children().childAt(0).type() ===
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      'textarea'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The second child of `MyToDoList`  should be a `br`  element.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mockedComponent.find('MyToDoList').children().childAt(1).type() === 'br'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								The third child of `MyToDoList`  should be a `button`  element.
							 
						 
					
						
							
								
									
										
										
										
											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(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mockedComponent.find('MyToDoList').children().childAt(2).type() ===
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      'button'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								The state of `MyToDoList`  should be initialized with `toDoList`  as an empty array.
							 
						 
					
						
							
								
									
										
										
										
											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(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const initialState = mockedComponent.state();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      Array.isArray(initialState.toDoList) === true & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      initialState.toDoList.length === 0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The state of `MyToDoList`  should be initialized with `userInput`  as an empty string.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const mockedComponent = Enzyme.mount(React.createElement(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const initialState = mockedComponent.state();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      typeof initialState.userInput === 'string' & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      initialState.userInput.length === 0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								When the `Create List`  button is clicked, the `MyToDoList`  component should dynamically return an unordered list that contains a list item element for every item of a comma-separated list entered into the `textarea`  element.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								(() => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const mockedComponent = Enzyme.mount(React.createElement(MyToDoList));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const simulateChange = (el, value) =>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    el.simulate('change', { target: { value } });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const state_1 = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return mockedComponent.find('ul').find('li');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const setInput = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return simulateChange(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mockedComponent.find('textarea'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      'testA, testB, testC'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const click = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return mockedComponent.find('button').simulate('click');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const state_2 = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const nodes = mockedComponent.find('ul').find('li');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return { nodes, text: nodes.reduce((t, n) => t + n.text().trim(), '') };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const setInput_2 = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return simulateChange(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mockedComponent.find('textarea'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      't1, t2, t3, t4, t5, t6'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const click_1 = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return mockedComponent.find('button').simulate('click');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const state_3 = () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const nodes = mockedComponent.find('ul').find('li');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return { nodes, text: nodes.reduce((t, n) => t + n.text().trim(), '') };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_state_1 = state_1();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_setInput = setInput();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_click = click();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_state_2 = state_2();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_setInput_2 = setInput_2();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_click_1 = click_1();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const awaited_state_3 = state_3();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    awaited_state_1.length === 0 & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      awaited_state_2.nodes.length === 3 & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      awaited_state_3.nodes.length === 6 & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      awaited_state_2.text === 'testAtestBtestC' & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      awaited_state_3.text === 't1t2t3t4t5t6'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								})();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# --seed--
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## --after-user-code--
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```jsx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ReactDOM.render(< MyToDoList  / > , document.getElementById('root'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## --seed-contents--
 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```jsx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								const textAreaStyles = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  width: 235,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  margin: 5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								class MyToDoList extends React.Component {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  constructor(props) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    super(props);
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // Change code 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 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    this.handleSubmit = this.handleSubmit.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.handleChange = this.handleChange.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  handleSubmit() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const itemsArray = this.state.userInput.split(',');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.setState({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      toDoList: itemsArray
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  handleChange(e) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.setState({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      userInput: e.target.value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  render() {
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:53:25 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    const items = null; // Change this line
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < textarea 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          onChange={this.handleChange}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          value={this.state.userInput}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          style={textAreaStyles}
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          placeholder='Separate Items With Commas'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        />
							 
						 
					
						
							
								
									
										
										
										
											2020-02-13 02:41:36 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        < br  / > 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        < button  onClick = {this.handleSubmit} > Create List< / button > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < h1 > My "To Do" List:< / h1 > 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        < ul > {items}< / ul > 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      < / div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											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
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								const textAreaStyles = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  width: 235,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  margin: 5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								class MyToDoList extends React.Component {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  constructor(props) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    super(props);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.state = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      toDoList: [],
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      userInput: ''
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    this.handleSubmit = this.handleSubmit.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.handleChange = this.handleChange.bind(this);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  handleSubmit() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const itemsArray = this.state.userInput.split(',');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.setState({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      toDoList: itemsArray
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  handleChange(e) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    this.setState({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      userInput: e.target.value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  render() {
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    const items = this.state.toDoList.map((item, i) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      return < li  key = {i} > {item}< / li > ;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < textarea 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          onChange={this.handleChange}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          value={this.state.userInput}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          style={textAreaStyles}
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          placeholder='Separate Items With Commas'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        />
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < br  / > 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        < button  onClick = {this.handleSubmit} > Create List< / button > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < h1 > My "To Do" List:< / h1 > 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        < ul > {items}< / ul > 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      < / div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
									
										
										
										
											2020-09-03 01:24:22 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								```