Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

current in this.input.current is misinterpreted as a prop #2101

Closed
atzec opened this issue Dec 31, 2018 · 4 comments
Closed

current in this.input.current is misinterpreted as a prop #2101

atzec opened this issue Dec 31, 2018 · 4 comments

Comments

@atzec
Copy link

atzec commented Dec 31, 2018

After update from 7.11.1 to 7.12.0 we started seeing this problem. Originally, the error occurred on a ref (e.g. this.input.current, where this.input was created in the constructor using React.createRef()), but here's a more abstract minimal example:

import React from "react";

export class D extends React.Component {

    constructor(props) {
        super(props);
        this.x = {y: "z"};
    }

    componentDidUpdate() {
        // react/prop-types: 'y' is missing in props validation
        console.log(this.x.y);
    }

}

Oddly enough, only componentDidUpdate() seems to be affected:

import React from "react";

export class D extends React.Component {

    constructor(props) {
        super(props);
        this.x = {y: "z"};
    }

    componentDidMount() {
        console.log(this.x.y); // NO error
    }

    componentDidUpdate() {
        console.log(this.x.y); // ERROR
    }

    render() {
        return this.x.y; // NO error
    }

}

(eslint 5.11.1)

@radoslawgrochowski
Copy link

radoslawgrochowski commented Dec 31, 2018

  shouldComponentUpdate(nextProps, nextState) {
    return (
      nextState.disable !== this.state.disable ||
      nextState.fieldCount !== this.state.fieldCount
    );
  }

error at nextState.fieldCount and nextState.disable

@ljharb
Copy link
Member

ljharb commented Dec 31, 2018

Not sure if this is fixed by the unreleased #2099 or #2098

@dzek69
Copy link
Contributor

dzek69 commented Jan 1, 2019

I can confirm this.

Using this.anything.anyName inside componentDidUpdate causes anyName to be caught as prop without propType.

Edit: @ljharb I can also confirm #2099 (commit 55e5fc1) fixes this issue.

@ljharb
Copy link
Member

ljharb commented Jan 1, 2019

Thanks for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants