over_react_prefer_use_or_create_ref

Severity: AnalysisErrorSeverity.INFO

Maturity: stable

Since 1.0.0

View the Project on GitHub workiva/over_react

PREFER to use the return value of createRef() as the ref field value.

GOOD:

class NavItemWrapperComponent extends UiComponent<NavItemWrapperProps> {
  final _navItemRef = createRef<NavItemComponent>();
  
  @override
  render() {
    return (NavItem()
      ..modifyProps(addUnconsumedProps)
      ..ref = _navItemRef
    )(props.children);
  }
}

BAD:

class NavItemWrapperComponent extends UiComponent<NavItemWrapperProps> {
  NavItemComponent _navItemRef;
  
  @override
  render() {
    return (NavItem()
      ..modifyProps(addUnconsumedProps)
      ..ref = (ref) { _navItemRef = ref; }
    )(props.children);
  }
}
Read more about createRef()