From bc8efb5541190285cc69a9cc6b965988334b3de9 Mon Sep 17 00:00:00 2001 From: Amir Hilal Date: Tue, 5 Mar 2019 02:38:40 +0300 Subject: [PATCH] Solution to spread operators in Redux challange (#34268) --- .../index.md | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/guide/english/certifications/front-end-libraries/redux/use-the-spread-operator-on-arrays/index.md b/guide/english/certifications/front-end-libraries/redux/use-the-spread-operator-on-arrays/index.md index da448c5380..79af8c61b6 100644 --- a/guide/english/certifications/front-end-libraries/redux/use-the-spread-operator-on-arrays/index.md +++ b/guide/english/certifications/front-end-libraries/redux/use-the-spread-operator-on-arrays/index.md @@ -2,9 +2,30 @@ title: Use the Spread Operator on Arrays --- ## Use the Spread Operator on Arrays - -This is a stub. Help our community expand it. - -This quick style guide will help ensure your pull request gets accepted. - + + +## 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); +```