Skip to content

Instantly share code, notes, and snippets.

@brookslybrand
Last active August 28, 2019 19:49
Show Gist options
  • Select an option

  • Save brookslybrand/46bb919063be9c755b5fbc64aeb2ffe6 to your computer and use it in GitHub Desktop.

Select an option

Save brookslybrand/46bb919063be9c755b5fbc64aeb2ffe6 to your computer and use it in GitHub Desktop.
const reducer = produce((state, action) => {
// eslint-disable-next-line default-case
switch (action.type) {
case REVERSE: {
state.reverse();
break;
}
case SET_OPTION: {
const { id, option } = action;
const itemOptions = state.find(item => item.id === id).options;
itemOptions[option].value = !itemOptions[option].value;
break;
}
case RESET_OPTIONS: {
state.forEach(({ options }) =>
Object.values(options).map(option => (option.value = false))
);
break;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment