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

Apply on start? #240

Closed Maadtin closed 4 years ago

Maadtin commented 4 years ago

How to apply on component render? only works when resizing, thanks <3

yocontra commented 4 years ago

@Maadtin The constraints are applied on render and then listens for further changes. Can you post an example of your code?

Maadtin commented 4 years ago

@contra Yes sure look:

function Index() {

    const [selectedType, setSelectedType] = useState('animes');
    const isTabletOrDesktop = useMediaQuery({minWidth: 1000});

    return (
            <Content />
            {isTabletOrDesktop && <Sidebar />
    )
}

When I reload the page <Sidebar /> component is visible but If I resize the mediaquery applies and It disappear just as I would expect but the problem is then I reload the page above 1000px It should appear but It doesn't...

yocontra commented 4 years ago

Could you make a codepen/jsfiddle/etc. that reproduces the issue?

yocontra commented 4 years ago

Closing since I haven't gotten a response. Will reopen if you have a reproduction available.