我使用WebStorm来实现React JS,并且我得到了这个' Unresolved variable warning'通过所有道具。
但是一切都没有问题,语言被定义,它存在。 代码有效,我的应用没有任何问题。
这就是我在Languages & Frameworks > JavaScript > Libraries
知道如何避免这些警告吗?
更新
发生这种情况的代码示例。第一个父组件:
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>
)
}
}
语言是对象{lowestPrice: "Lowest price", mileage: "Mileage", ....}
然后我尝试获取这些道具的组件,它可以工作,但我得到警告他们没有解决:
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>
);
}
}
答案 0 :(得分:2)
使用解构赋值:
let language = this.props.language;
而是function arrDiff(xs, yx, d) {
const apply = f => x => f(x);
const flip = f => y => x => f(x)(y);
const concat = y => xs => xs.concat(y);
const createMap = xs => new Map(xs);
const filter = f => xs => xs.filter(apply(f));
//left difference
const differencel = xs => yx => {
const zs = createMap(yx);
return filter(([k, x]) => zs.has(x) ? false : true)(xs);
};
if (d == 'left') return differencel
//right difference
const difference2 = flip(differencel);
if (d == 'join') return difference2;
//union
if (d == "union") {
const map = new Map([...xs, ...yx]);
return map;
}
// symmetric difference
const difference = yx => xs => concat(differencel(xs)(yx))
(flip(differencel)(xs)(yx));
return difference;
}
const xs = [
['a', 1],
['b', 2],
['c', 2],
['d', 3],
['e', 4],
['f', 5]
];
const ys = [
['g', 0],
['h', 1],
['f', 2],
['b', 3],
['c', 3],
['a', 3],
['e', 6],
['h', 7]
];
console.log(arrDiff(xs, ys, 'left'));