Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 846 Bytes

react-hooks-strict-return.md

File metadata and controls

41 lines (31 loc) · 846 Bytes

Restrict the number of returned items from React hooks. (react-hooks-strict-return)

Where possible, return two or fewer values from a hook, and return them in a tuple, like React.useState (if you have no choice but to return more than three values, return them as a single object instead).

Rule Details

Examples of incorrect code for this rule:

function useFoo() {
  const bar = 'bar';
  const baz = 'baz';
  const qux = 'qux'
  return [bar, baz, qux];
}

Examples of correct code for this rule:

function useFoo() {
  const bar = 'bar';
  const baz = 'baz';
  return [bar, baz];
}
function useFoo() {
  return {
    bar: 'bar',
    baz: 'baz',
    qux: 'qux',
  };
}

When Not To Use It

If you do not want to enforce a stict return style from React hooks, you can safely disable this rule.