Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

eslint mobx/missing-observer rule false positive with forwardRef #3908

Closed
TimMoore opened this issue Jul 24, 2024 · 2 comments · Fixed by #3909
Closed

eslint mobx/missing-observer rule false positive with forwardRef #3908

TimMoore opened this issue Jul 24, 2024 · 2 comments · Fixed by #3909
Labels

Comments

@TimMoore
Copy link

Intended outcome:

I am using the mobx-react observer function with a component that is also wrapped with React forwardRef, such as the example below:

import { observer } from 'mobx-react';
import { ForwardedRef, forwardRef } from 'react';

const MobxObserverForwardRefExample = observer(
  forwardRef(function MobxObserverForwardRefExample({ name }: { name: string }, ref: ForwardedRef<HTMLHeadingElement>) {
    return (
      <div>
        <h1 ref={ref}>Mobx Observer Forward Ref Example {name}</h1>
      </div>
    );
  }),
);

export default MobxObserverForwardRefExample;

I am extending plugin:mobx/recommended in my .eslintrc.json.

Actual outcome:

With the mobx/missing-observer eslint rule enabled, it fails to detect the observer wrapper on this component because of the forwardRef call in between:

MobxObserverForwardRefExample.tsx
  5:14  warning  Component `MobxObserverForwardRefExample` is missing `observer`  mobx/missing-observer

✖ 1 problem (0 errors, 1 warning)
  0 errors and 1 warning potentially fixable with the `--fix` option.

How to reproduce the issue:

I wasn't able to quickly figure out how to make ESLint work in a CodeSandbox, but this is easy to reproduce with the component above.

Versions

  • React 18.3.1
  • MobX 6.12.0
  • mobx-react 9.1.0
  • eslint-plugin-mobx 0.0.10
@urugator
Copy link
Collaborator

Fixed in eslint-plugin-mobx@0.0.11

@TimMoore
Copy link
Author

Amazing! Thanks for the quick fix.

taj-p pushed a commit to taj-p/mobx that referenced this issue Aug 30, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants