Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Different mobile layout for a component in ReactJs

How can we create a completely different (mobile type layout) for a component (having a different desktop type layout) using ReactJs. (Not Responsive , responsive is something css has to take care of.) It should be different layout for the component i.e here Creating a page with a menu(header menu) for desktop screens which becomes a navigation sidebar with logo on small screen.

like image 573
rajit Avatar asked Jan 05 '17 06:01

rajit


1 Answers

Honestly, a simple resposive css layout may be the best solution, but the steps are to

1) Detect in JS if user in on mobile or desktop. For example this question has a good suggestion as an answer: Detecting a mobile browser

2) Use it to decide in your root component that which layout to use:

function isMobile() {
  // some js way to detect if user is on a mobile device
}

class Root extends Component {
  render() {
    return isMobile() ? ( <MobileLayout /> ) : ( <DesktopLayout /> )
  }
}
like image 125
jakee Avatar answered Oct 27 '22 08:10

jakee