DEV Community

Discussion on: Whenever we see (d) => setData(d), what can we think about?

Collapse
 
sargalias profile image
Spyros Argalias

Yes, completely agree. After getting used to functional programming the redundancy of .then(d => something(d)); always sticks out to me as .then(something); is equivalent.

It's as though someone was writing:

function add5(a) {
  function nowActuallyRunTheThing(a) {
      return 5 + a
  }
  return nowActuallyRunTheThing(a);
}
Enter fullscreen mode Exit fullscreen mode

Instead of just:

function add5(a) {return a + 5};
Enter fullscreen mode Exit fullscreen mode

Sometimes I take it a step further and also shorten the res.json() line, although this one depends because sometimes it can be more confusing. For example:

import { invoker } from 'ramda';
fetch("...")
  .then(invoker(0, 'json')) // equivalent to (res => res.json())
Enter fullscreen mode Exit fullscreen mode