import React, {Component, useState, useEffect} from 'react';
import {connect} from 'react-redux';
import BigHeader from './bigHeader';
import SmallHeader from './smallHeader';
function isSmall() {
if(this.windowWidth < 1307){
return true;
}
return false;
}
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
function determineWidth() {
const width = window.innerWidth;
setWindowWidth(width);
isSmall(width);
}
useEffect(() => {
window.addEventListener("resize", determineWidth);
return function() {
window.removeEventListener("resize", determineWidth);
}
})
class Header extends Component {
render() {
return this.isSmall() ? <SmallHeader/> : <BigHeader/>
}
}
// export default connect(mapStateToProps, page);
export default Header;
我从这条线得到一个错误const [windowWidth, setWindowWidth] = useState(window.innerWidth);
我试图在屏幕 < 1307 时返回一个移动/较小的标题,并在它高于该标题时返回一个不同的标题。