yocontra / react-responsive

CSS media queries in react - for responsive design, and more.
https://contra.io/react-responsive
MIT License
7.04k stars 298 forks source link

useMediaQuery hook should re-render page on window resize #230

Closed sergeyzwezdin closed 5 years ago

sergeyzwezdin commented 5 years ago

Thank you for React Hooks support.

But there is a problem with the useMediaQuery hook:

const Component = () => {
    const isMobile = useMediaQuery({ query: '...' });
    return <div>{ !isMobile ? 'Desktop' : 'Mobile' }</div>;
};

Initially, it works fine, but it doesn't force component re-render on window resize. I believe it should re-render the component on resizing.

sergeyzwezdin commented 5 years ago

Hm, it looks like I used wrong media query. It works as expected.

wazcov commented 2 years ago

@sergeyzwezdin What did you change? I'm using Chakra UI and on resize the hook doesn't seem to get called

sergeyzwezdin commented 2 years ago

@wazcov I didn't try it with Chakra UI. In my case it was the wrong query value.