Hacker News new | ask | show | jobs
by disillusionist 426 days ago
you can do this rather easily by returning an object rather than a primitive. if you're using a language like TypeScript, destructuring the resulting returned object is rather trivial and (in my opinion) delightful to read. eg

  function combineNames({ first, last }) {
    const fullName = `${first} ${last}`;
    return { fullName };
  }
  const { fullName } = combineNames({first: 'John', last: 'Doe' });
1 comments

For some reason React prefers to return arrays. I never understood the reason.

  const [state, setState] = useState(initialState)
instead of

  const {state, setState} = useState(initialState)