Solution to spread operators in Redux challange (#34268)

This commit is contained in:
Amir Hilal
2019-03-05 02:38:40 +03:00
committed by Randell Dawson
parent dcb7e22b08
commit bc8efb5541

View File

@ -2,9 +2,30 @@
title: Use the Spread Operator on Arrays
---
## Use the Spread Operator on Arrays
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/front-end-libraries/redux/use-the-spread-operator-on-arrays/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
## Solution
```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);
```