Skip to content

False positive for function-component-definition when function returns null #2554

Closed
@UncleClapton

Description

@UncleClapton

I hava a function which react/function-component-definition is falsely reporting as a function component. This only seems to occur when null is returned at the end of a function.

My rule config is:

'react/function-component-definition': ['error', {
  namedComponents: 'function-declaration',
  unnamedComponents: 'arrow-function',
}],

function that triggers a false positive:

const selectAvatarByUserId = (state, id) => {
  const user = selectUserById(state, id)

  if (user) {
    return user.attributes.image || `//api.adorable.io/avatars/${user.id}`
  }

  return null
}

Removing return null or returning any other value fixes the error. I was able to get around this by reversing my if statement, but I'm still reporting this as a potential bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions