首页 > 解决方案 > How to fix eslint prefer-destructuring if we want to override defined variable?

问题描述

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

标签: javascriptecmascript-6eslint

解决方案


推荐阅读