Reactjs Material-UI Hidden component
Video:
You can also watch the below video to learn on Hidden:
Breakpoint up and down:
We can use up or down property with a specific breakpoint for Hidden. For example, if we use xlUp, it will be hidden for all screen sizes at breakpoints xl and above.
If we use xlDown, it will be hidden for all screen sizes at breakpoints xl and below.
e.g.
<Hidden smDown>...</Hidden>
<Hidden smUp>....</Hidden>
Breakpoint only:
We can use only property to hide the children at one or multiple breakpoints:
<Hidden only={['lg', 'xl']}>....</Hidden>
or
<Hidden only="lg">
React project:
Let's take a look at the below component:
import { Hidden, Paper } from "@material-ui/core";import "./App.css";function App() {return (<div className="App"><Hidden smDown><Paper style={{ backgroundColor: "red", width: 200, height: 200 }} /></Hidden><Hidden mdUp><Paper style={{ backgroundColor: "blue", width: 200, height: 200 }} /></Hidden><Hidden only="md"><Paper style={{ backgroundColor: "green", width: 200, height: 200 }} /></Hidden></div>);}export default App;
- It has three Paper components wrapped with Hidden.
- Each Paper component is wrapped in Hidden with different properties.
- If you run it, the red paper will be hidden for sm and lower screens, blue paper will be hidden for md and above, green paper will be hidden for md.