-
Notifications
You must be signed in to change notification settings - Fork 198
react-unused-props-and-state fails with SFC's #339
Comments
Can you post a sample of one of your SFCs? |
Here is one possible syntax for SFC:
|
I am also experiencing this issue, Reproductioninterface Props {
children?: React.ReactNode;
heading: string;
className?: string;
}
export function TestComponent(props: Props) {
return (
<div className={props.className || ''}>
<h3>{props.heading}</h3>
{props.children}
</div>
)
}
export default TestComponent; Output
|
Sorry about the late response, just saw there was a comment. Here's an example SFC. Both properties are being flagged as unused. tslint.json
SFC
|
I'm having this issue too |
Any updates on this issue? |
None yet. I looked at it briefly, but a proper solution that covers all the destructuring corner cases is fairly time consuming to write. I am currently on vacation but have reserved next Monday to continue to look into this. |
@HamletDRC Any news on this? |
Nothing yet. |
Ok, I just had to look this up: SFC === Stateless Functional Component. Been using them for years and didn't think of that as the abbreviation... |
Also seeing this. For some reason, this fails: interface Props {
children: JSX.Element | JSX.Element[];
className: string;
}
const ButtonGroup: SFC<Props> = (props: Props) => {
return (
<div className={props.className}>
{props.children}
</div>
)
}; But changing interface SomeRandomProps{
children: JSX.Element | JSX.Element[];
className: string;
}
const ButtonGroup: SFC<SomeRandomProps> = (props: SomeRandomProps) => {
return (
<div className={props.className}>
{props.children}
</div>
)
}; It's not ideal to have to call |
The comment above is pretty frightening. Can someone elaborate on why provided works and naming stuff Props doesn't? Let's write code, not magic.. |
It passes probably because |
Any progress on this? I just posted an issue referencing this exact issue almost 2 years after this was posted :( |
@nextriot it's still accepting PRs if anybody (you? 😉) is up for contributing a solution to the issue. As HamletDRC noted, a proper solution that covers all the destructuring corner cases is fairly time consuming to write. Unless you have the time to start on it yourself, I wouldn't expect a solution to this anytime soon. |
Thanks for taking the time to reply @JoshuaKGoldberg. If I knew where (or even how) to start, I'd very much like to contribute. Any idea what developers are doing in the meantime? Is there some hack that can be employed? |
Yeah contributing docs are something that could be a bit spruced up with TSLint (open issues) ☹... A few handy docs on getting started:
Hope this helps, and feel free to reach out on Gitter or Twitter (publicly or DMs) if you have any questions! It'd be great to have more people tackling these issues! |
See: microsoft/tslint-microsoft-contrib#339 Apparently when using React.SFC there are some issues. I don't understand why renaming has any effect but it works
See: microsoft/tslint-microsoft-contrib#339 Apparently when using React.SFC there are some issues. I don't understand why renaming has any effect but it works
See: microsoft/tslint-microsoft-contrib#339 Apparently when using React.SFC there are some issues. I don't understand why renaming has any effect but it works
This rule appears to only work with
this.props
calls. So SFC's don't work because there is nothis
pointer.Also, once you destructure props/state, it assumes all keys are used. Even if you only reference some of the props in the destructure:
The text was updated successfully, but these errors were encountered: