Search code examples
react-md

Using react-md, what is the best way to check for mobile, tablet or desktop client?


Is there a general way of determining whether a device is mobile/tablet or desktop?

I.e. something like the following:

<SomeComponent defaultVisible={props.isMobile ? true : false} />

I see there is a 'class function' - getCurrentMedia() - https://react-md.mlaursen.com/components/navigation-drawers?tab=1#drawertypes

But I don't know how to use this


Solution

  • On further investigation:

    A class function is a function defined as a static reference on a class. In my case I'm using the NavigationDrawer component, which is a component defined as a JavaScript class - so a class function getCurrentMedia is accessed like the following:

    NavigationDrawer.getCurrentMedia()