Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
        );
    }
}
like image 402
Boky Avatar asked Nov 28 '16 09:11

Boky


1 Answers

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

like image 81
dimidrol dimidrola Avatar answered Sep 17 '22 15:09

dimidrol dimidrola