From ffe43d10910a1600decbc41e3e178340190bcd28 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 5 May 2018 09:57:54 -0500 Subject: [PATCH] Refactored remove habit to pass the new tests - Currently there is a bug with React Native where the rest operator does not work when destructuring with an integer key. - Casting to a string is a temporary fix. - https://github.com/facebook/react-native/issues/18273 --- containers/habits/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/containers/habits/index.js b/containers/habits/index.js index 8ae00e7..0ce52ce 100644 --- a/containers/habits/index.js +++ b/containers/habits/index.js @@ -19,6 +19,7 @@ class HabitsContainer extends Container { addHabit = ({ title, frequency, timesPerDay }) => { const nextState = { ...this.state.habits, + [habitId]: { frequency, status: STATUS.ACTIVE, @@ -33,7 +34,7 @@ class HabitsContainer extends Container { }; removeHabit = id => { - const nextState = this.state.habits.filter(habit => habit.id !== id); + const { [String(id)]: _, ...nextState } = this.state.habits; this.setState({ habits: nextState }); };