1
我正在做一个条件在我的shouldComponentUpdate方法,如果条件匹配返回true,否则返回false ...但是我仍然得到“返回未定义,而不是一个布尔...”作为标题暗示。ReactJS警告:Thumbnails.shouldComponentUpdate():返回undefined而不是布尔值。请确保返回true或false
这里是我的方法:*注意:如果我没有它自动假设nextProps.props.length是0甚至当其超过0
shouldComponentUpdate(nextProps){
setTimeout(()=>{
console.log(nextProps.props, nextProps.props.length);
if(nextProps.props.length > 0){
return true;
}else{
return false;
}
},1000)
}
你为什么使用'setTimeout'? –
你正试图实现什么? –
无论setTimeout长度是否为0,它都返回为0,而不管该长度是否为0。我想通了,但我只是在shouldcomponentupdate中使用this.state not this.props或nextProps ...所以这个问题解决了...现在另一个问题,虽然 – moesh