react icon indicating copy to clipboard operation
react copied to clipboard

componentWillRecieveProps warning

Open lubelski opened this issue 11 years ago • 8 comments

Can you please implement a warning for when a component tries to implement the componentWillRecieveProps method instead of the componentWillReceiveProps method?

Almost every React person I know has been bitten by this and it always take 30 minutes of debugging to find and then you feel like a dummy the rest of the day.

lubelski avatar Jun 05 '15 15:06 lubelski

Sure, we have another for componentShouldUpdate (which is the common "typo" of shouldComponentUpdate). Would it be cool if we just said "I BEFORE E EXCEPT AFTER C, and also other times because English is silly and inconsistent."?

zpao avatar Jun 05 '15 17:06 zpao

I'd like to take a stab at this.

@zpao Would adding a noop fn that returns the warning wrapped in a __DEV__ block in https://github.com/facebook/react/blob/master/src/isomorphic/classic/class/ReactClass.js make sense?

Or is there a common place for handling errors for invalid methods / prop names?

Tests required for this?

jamischarles avatar Jun 05 '15 19:06 jamischarles

I think it probably belongs alongside the warning for componentShouldUpdate, which should already be dev only.

zpao avatar Jun 05 '15 19:06 zpao

This looks like the job for a linter not the React library?

raybooysen avatar Jun 06 '15 12:06 raybooysen

@raybooysen, Ideally, but I don't think many linters can check for undefined variables across imports, and some of the react userbase isn't using one. Whether we should support that use-case or not is a valid question though.

bgw avatar Jun 07 '15 00:06 bgw

Closed via #4045.

Yes, ideally this is a part of lint. I think it could be cool if https://github.com/yannickcr/eslint-plugin-react has a rule for it - feel free to suggest it to @yannickcr (and/or write it :wink:)

zpao avatar Jun 08 '15 22:06 zpao

@zpao I was not very comfortable with typos detection (see my response here) but if React start to "officially" warn about some typos I think we can try to mimic it's behavior (like we did for no-unknonw-property) to warn the developer before code execution.

yannickcr avatar Jun 09 '15 13:06 yannickcr

@yannickcr Your call. We try to keep it pretty minimal in core, this 1 added here after 2 years, componentShouldUpdate added a lot earlier, incorrectly-cased DOM props a while ago. There's another for mistyped event handlers. We'll adjust with more or less later I'm sure. I'm currently on a "machines should fix all my problems" kick so I like more linting. If you don't add it that's totally your call - I'm appreciative of the rules you do have :) If somebody wants to add their own rules, eslint makes this super easy so they can write their own.

zpao avatar Jun 09 '15 16:06 zpao