Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Trying to set window height but it gives an error in react.js [duplicate]

$
0
0

I use useState to get the window height but it gives a runtime error saying that window is not defined. Do you know why

Here's the code:

let [winHeight,setWinHeight] = useState(window.innerHeight)
useEffect(() => {          const list = []          for (var i=0;i<datas.length;i++){               const t = datas[i].title               const res = handleResize(i + 2)               list.push(<li ref={resl[i + 1]} style={{top: "20px",left: res +"px"}}><Anchor href={datas[i].link || `/${t.replace(/ /g, "_")}`}><a onClick={() => closeNav()} onMouseOver={() => setHovering(i)}>{t}</a></Anchor></li>)          }          setWinHeight(window.innerHeight)          setLinks(list)     }, [winHeight])

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>