

Reading tutorials are a great way to learn React, but there is no replacement for hands-on coding. The grid creates visual consistency between layouts while allowing flexibility across a wide variety of designs. Enjoyed this tutorial? Here's a special bonus. This hook will work on any server rendered React app, such as Gatsby and Next.js. utils/useWindowSize.jsĮxport default function useWindowSize() js in our utilities (utils) folder, the same name as the hook useWindowSize and I’ll import React (to use hooks) while exporting the custom hook.
#React responsive layout how to#
How to create the custom hookįirst, we’ll create a new file. Instead of bringing an entire third-party library, however, I decided to create my own hook that would provide the dimensions of the window, both the width and height. Having a responsive layout is an important component of user interface (UI) design. React Material Admin comes with various components, a straightforward design with form, table, and login pages. This one builds on top of the Material-UI framework with a simple responsive design. Previously, I was using a hook from the a library called react-use to add this functionality. React Material Admin is a react dashboard template that helps you to kickstart your next project. To do this we could use a media query with CSS, or we could use a custom React hook to give us the current size of the page and hide or show the links in our JSX. As I decrease the size of the page, I want to show fewer links:


How do you make your React applications responsive for any sized device? Let's see how to do so by making our own custom React hook.Īt the top of my React site is a Header component.
