| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | title: Use the Spread Operator on Arrays | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | ## Use the Spread Operator on Arrays
 | 
					
						
							| 
									
										
										
										
											2019-03-05 02:38:40 +03:00
										 |  |  | <!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds  --> | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-05 02:38:40 +03:00
										 |  |  | ## Solution
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-05 02:38:40 +03:00
										 |  |  | ```javascript | 
					
						
							|  |  |  | const immutableReducer = (state = ['Do not mutate state!'], action) => { | 
					
						
							|  |  |  |   switch(action.type) { | 
					
						
							|  |  |  |     case 'ADD_TO_DO': | 
					
						
							|  |  |  |       // don't mutate state here or the tests will fail | 
					
						
							|  |  |  |       let arr = [...state]; | 
					
						
							|  |  |  |       arr.push(action.todo); | 
					
						
							|  |  |  |       return arr; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return state; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const addToDo = (todo) => { | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     type: 'ADD_TO_DO', | 
					
						
							|  |  |  |     todo | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const store = Redux.createStore(immutableReducer); | 
					
						
							|  |  |  | ``` |