jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
8.94k stars 2.77k forks source link

no-unused-prop-types false positive with createPortal and forwardRef #3475

Open reintroducing opened 1 year ago

reintroducing commented 1 year ago

I've got a component where the containing div is wrapped with createPortal. If I remove the createPortal, all of my propTypes are correctly used, but if I re-add the createPortal to surround the div, all of my propTypes get marked as no-unused-prop-types. Not sure whats going on here but figured I'd point it out in case nobody has ever reported this (which doesn't seem anyone has, I searched both open and closed issues with no success around this).

himanshu007-creator commented 1 year ago

Hey @reintroducing , can you share a codespace sample? like a stackblitz link? Reference: https://stackblitz.com/

reintroducing commented 1 year ago

@himanshu007-creator Is there a pre-existing template set up already with the rules in place for this repo? Or do I have to create a new one to demonstrate this issue?

himanshu007-creator commented 1 year ago

You can create a blank project to demonstrate the code that you are referring to.

reintroducing commented 1 year ago

@himanshu007-creator right, i guess what i meant is if there is a pre-existing template that takes care of the setup of defining eslint, adding this plugin, and being ready to show any subsequent issues that may be present, but i'm assuming there isn't, so i'll create one from scratch.

himanshu007-creator commented 1 year ago

Yeah you would have to create a fresh one. Sorry for my misinterpretation 🙂

reintroducing commented 1 year ago

Here you go: https://stackblitz.com/edit/vitejs-vite-xkspmk

I updated the title because its actually when createPortal is used within a forwarded ref. FooNoPortal.jsx and FooPortal.jsx are identical except that the NoPortal doesn't create a portal and the other does. The one with the forwarded ref and the portal produces the error in the terminal:

src/FooPortal.jsx(10,3): 'name' PropType is defined but prop is never used react/no-unused-prop-types

reintroducing commented 1 year ago

@himanshu007-creator just following up to see if the SB link above worked for you and you are able to verify this is a real issue?

giovannipds commented 1 year ago

We're facing false positives in our project too