1

export const foo = (param) => {
  const nextState = { fetching: false };
  let value = null;

  switch (param.key) {
    case someCase:
      value = 2;
      break;
    default:
      value = param.value;
      break;
  }

  nextState[param.key] = value;

  return state.merge(nextState);
};

From the code above, line value = param.value is getting eslint exception, saying prefer destructuring. I understand what destructuring is but wasnt sure how to apply in this case above because we alread have let value = null

Isaac
  • 12,042
  • 16
  • 52
  • 116
  • 2
    `({ value } = param);`, though that rule seems just a bit odd if it's requiring you to destructure into an existing variable as well, IMO. You might consider using an object instead of `switch` if possible, it's less verbose and less error-prone (your current code has said error - you aren't `break`ing in first case) – CertainPerformance May 25 '19 at 05:57
  • @CertainPerformance: oh yes, it was just a sample case, i will update it, but this syntax `({ value } = param)` seems to be odd to me haha – Isaac May 25 '19 at 06:08

0 Answers0