Skip to content

Instantly share code, notes, and snippets.

@ohansemmanuel
Created September 14, 2017 19:17
Show Gist options
  • Save ohansemmanuel/60c7506de3336b84f34d058dc8d2d852 to your computer and use it in GitHub Desktop.
Save ohansemmanuel/60c7506de3336b84f34d058dc8d2d852 to your computer and use it in GitHub Desktop.
export function updateCardTextReducer(cardId, event) {
event.persist();
return function updateCard(state) {
const {cards, cardIds} = state;
const index = cardIds.indexOf(cardId);
const card = getCardById(cardId, cards);
const newCardUpdatedText = {
...card,
text: event.target.value
};
const newCards = [
...cards.slice(0,index),
newCardUpdatedText,
...cards.slice(index + 1)
];
const newState = {
...state,
cards: newCards
};
setToLocalStorage(APP_STATE_EDITING, newState);
return newState;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment