over_react_unnecessary_key

Severity: AnalysisErrorSeverity.INFO

Maturity: stable

Since 1.0.0

View the Project on GitHub workiva/over_react

PREFER omitting props.key when an element is the only element in an iterable, or when it is not placed within an iterable.

GOOD:

@override
render() {
  return Dom.ul()(
    Dom.li()(
      'item 1',
    ),
    Dom.li()(
      'item 2',
    ),
  );
}

BAD:

@override
render() {
  return Dom.ul()(
    (Dom.li()..key = 1)(
      'item 1',
    ),
    (Dom.li()..key = 2)(
      'item 2',
    ),
  );
}

BAD:

@override
render() {
  return Dom.ul()([
    (Dom.li()..key = 1)(
      'the only item',
    ),
  ]);
}