Boky
Boky

Reputation: 12054

WebStorm unresolved variable warning

I use WebStorm for React JS and I'm getting this 'Unresolved variable warning' by all props.

enter image description here

But everything works without problems, language is defined, it exists. Code works, I don't have any issues with my app.

This is what I have inside Languages & Frameworks > JavaScript > Libraries

enter image description here

Any idea how to avoid those warnings?

UPDATE

Code example where that happens. First parent component :

import ExpirationTimer from '../../common/expirationTimer';

export default class ListView extends React.Component {
    render (){
        const language = this.props.language;
        let expirationDate = "Wed May 10 2017 15:58:59 GMT+0200";

        return (
            <div>
                <ExpirationTimer expirationDate={expirationDate} language={language}/>
            </div>
        )
    }
}

Where language is an object {lowestPrice: "Lowest price", mileage: "Mileage", ....}

And then the component where I try to get those props, it works, but I get warning that they are unresolved :

 export default class ExpirationTimer extends React.Component {
    constructor(props){
        super(props);

        this.state = {                
            expirationDate: this.props.expirationDate // Here I get the warning
        };
    }

    render(){
        let language = this.props.language; // Here I get the warning


        return (
            <div>
                .....
            </div>
        );
    }
}

Upvotes: 7

Views: 7575

Answers (1)

dimidrol dimidrola
dimidrol dimidrola

Reputation: 129

use destructuring assignment: let {language} = this.props instead let language = this.props.language;

Upvotes: 4

Related Questions