I have 2 headers. I want to render the first one when width > 768px, and second one when < 768.
I tried this :
const [isMobileResponsive, setIsMobileResponsive] = useState(false);
useEffect(() => {
setIsMobileResponsive(window.innerWidth < 768);
} , [window.innerWidth]);
return (
!isMobileResponsive ?
<p>header1</p>
:
<p>header2</p>
)
The problem with this : when I go to chrome responsive feature, and resize the size of the screen, React does not re-render and don't change the header. I have to reload the page to get the new Header.
How can I do this ?
Thank you very much.