Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 参考电流为空_Javascript_Reactjs - Fatal编程技术网

Javascript 参考电流为空

Javascript 参考电流为空,javascript,reactjs,Javascript,Reactjs,调用resize事件时,我正在记录ref的当前值。调整窗口大小时,ref的当前值为null 类弹出扩展了React.PureComponent{ 建造师(道具){ 超级(道具) this.popoutRef=React.createRef()//current=null } isWithinViewPort=()=>{ console.log('popoutRef',this.popoutRef) } componentDidMount(){ window.addEventListener('r

调用resize事件时,我正在记录ref的当前值。调整窗口大小时,ref的当前值为null

类弹出扩展了React.PureComponent{
建造师(道具){
超级(道具)
this.popoutRef=React.createRef()//current=null
}
isWithinViewPort=()=>{
console.log('popoutRef',this.popoutRef)
}
componentDidMount(){
window.addEventListener('resize',this.isWithinViewPort)
}
组件将卸载(){
window.removeEventListener('resize',this.isWithinViewPort)
}
render(){
const{id,children,borderColor,style,hidden,pointerLeft,pointerRight}=this.props
如果(隐藏){
返回空
}
返回(
{儿童}
)
}
}
代码在
/components/popoout.js
第46行。

你的问题是什么

ref
仅在安装并呈现组件时设置。您的
render
方法具有以下条件:

if (hidden) {
  return null
}
这意味着,如果
弹出窗口
被隐藏,将不会有ref