📅  最后修改于: 2022-03-11 15:02:43.408000             🧑  作者: Mango
function WindowSizeList({ url }) {
const [windowWidth, setWindowWidth] = useState(window.innerWidth)
const [items, setItems] = useState([])
const updateWindowWidth = () => {
setWindowWidth(window.innerWidth)
}
useEffect(() => {
setItems(CustomApi.getList(url))
}, [url])
useEffect(() => {
window.addEventListener('resize', updateWindowWidth)
return () => {
window.removeEventListener('resize', updateWindowWidth)
}
}, [])
return (
<>
Window Width: {windowWidth}
{items.map(item => {
return {item}
})}
>
)
}