Skip to content

eslint react hooks rules do not work when a component is wrapped in observer #4594

@javiergonzalez-synth

Description

@javiergonzalez-synth

This is not really a but report in MobX itself (sorry), but I just wanted to point out that react-hooks eslint rules (other than dependency checking) are not working at all for components wrapped in observer (or wrapped in any function other than react built-ins like memo/forwardRef) for that matter.

There's an (ugly) workaround though, which is wrapping a named function:

const Component = observer(function Component() {
  ...
})

that perhaps could be added to the docs.

I created a fix 3 weeks ago - facebook/react#34608 - but it seems it didn't gain much traction 😔, which is a shame because these rules are useful even in the mobx-react world (and even worse, I found they stopped working by pure chance)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions