mobily / ts-belt

🔧 Fast, modern, and practical utility library for FP in TypeScript.
https://mobily.github.io/ts-belt
MIT License
1.11k stars 31 forks source link

How would you convert a regular ol' event handler to use ts-belts magical 🌈 functional approach? #38

Closed martisj closed 2 years ago

martisj commented 2 years ago

example event handler in React:

const onChange = (event: ChangeEvent<HTMLInputElement>, index: number) => {
  setTupleState((prev) => {
    return [...prev.slice(0, index), event.target.value, ...prev.slice(index + 1)];
  });
};

With eslint-plugin-functional/lite rules I get the following errors:

mobily commented 2 years ago

@martisj here is my developer-friendly eslint config (at least to me) :)

'functional/functional-parameters': 0,
'functional/no-return-void': 0,
'functional/no-conditional-statement': [2, { allowReturningBranches: true }],
'functional/no-expression-statement': 0,
'functional/no-mixed-type': 0,
'functional/immutable-data': [2, { ignoreAccessorPattern: ['**.current'] }],
'functional/prefer-readonly-type': 2,

(simply adjust your eslint config to your needs, you don't have to use all "recommended" rules)