Skip to content

Rule for documenting effects #69

@kaisermann

Description

@kaisermann

Is your feature request related to a problem? Please describe.

A single useEffect can be easy to understand. However, multiple useEffect calls in a relatively complex application can be hard to understand.

Describe the solution you'd like

I propose a rule vtex/react-explicit-effects, or vtex/react-documented-effects, that looks for effect react hooks (not only useEffect) and enforces one of two ways to document the purpose of the hook:

  • Adding a comment above the hook call, explaining the effect use-case.
import { useEffect } from 'react'

const Potato = () => {
  // do this and do that
  useEffect(() => {
    /// ...
  })
}
  • Using a named function instead of an arrow function:
import { useEffect } from 'react'

const Potato = () => {
  useEffect(function doThisAndThat() {
    /// ...
  })
}

Describe alternatives you've considered

Leave people to document effects themselves (which is a big no-no)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions