How to display specific elements on a page at a specific screen resolution. A kind of mobile version for the site, something like media queries, only which will display a certain block of js (react) / html (jsx) code at a certain resolution
Advertisement
Answer
You can take a look at the answer on this similar question
If you’re using JSX
the usage should be wrapped into {}
for example:
JavaScript
x
12
12
1
render() {
2
return (
3
// ...
4
// In my knowledge JS event listeners are more taxing on the performance
5
{
6
if($(window).width() >= 1024){
7
return <div className="bigger-than-1024"> RENDERED CONDITIONALLY </div>
8
}
9
}
10
);
11
}
12
The better way to do this might be to still render it and then use CSS classes and media queries to not display it:
JavaScript
1
6
1
@media only screen and (min-width: 1023px) {
2
.bigger-than-1024 {
3
display: none;
4
}
5
}
6