Access variable from script inside React component
I am doing device detection on Node and sending this object to the client(React) inside of index.ejs
<script type="text/javascript">window.deviceType = <%- deviceType %></script>
Inside of React component if I console.log window.deviceType I see it running good but if I try to use it it says error, window is not defined.
For example, this is inside react component
return(
<div>
<Menu.Item>
{window.deviceType.isMobile ? (
<Link to="/">
<h1>React Boilerplate 23</h1>
</Link>
) : (
<div>PROBLEM</div>
)}
</Menu.Item>
<div type="button" onClick={() => console.log(window.deviceType)}>
XX
</div>
</div>
)
I can console.log it normal but it doesnt work when using logic so in the example above rendering doesnt work but console.log works.
The same stuff is happening if I try to do it like this
<script type="text/javascript">var deviceType = <%- deviceType %></script>