Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

media query for mobile in react file

import React, { Component } from 'react';

class App extends Component {
  constructor(props) {
    super(props)
    this.state = { matches: window.matchMedia("(min-width: 768px)").matches };
  }

  componentDidMount() {
    const handler = e => this.setState({matches: e.matches});
    window.matchMedia("(min-width: 768px)").addListener(handler);
  }
  render() {
    return (
      <div >
      {this.state.matches && (<h1>Big Screen</h1>)}
      {!this.state.matches && (<h3>Small Screen</h3>)}
      </div>
    );
  }
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: semantic UI react focus on input 
Javascript :: make the background color of page in the loading js 
Javascript :: javascript loop area 
Javascript :: Play css animation with JS onhover 
Javascript :: enviroment variable not getting recognised in NuxtJS 
Javascript :: how to find dublicates in string 
Javascript :: How to get a factorial number 
Javascript :: elte html if not updating 
Javascript :: tips and tricks for javascript 
Javascript :: check if div is collpased jqeruy 
Javascript :: symbols with object.assign 
Javascript :: how to disable spaces and tabs for a input:text 
Javascript :: how to send json data to server in android using volley 
Javascript :: setstate to false after 10 sec react native 
Javascript :: angular material nested tree 
Javascript :: open menu 
Javascript :: ng serve -- port 5200 
Javascript :: petrov attack 
Javascript :: node js passport local for sqlite 
Javascript :: get index after pushing value in array in js 
Javascript :: react native undedined map 
Javascript :: how to resolve click for div logging as parent too, in react 
Javascript :: create javascript array with no values 
Javascript :: Using Scrip as Web app 
Javascript :: crop go 
Javascript :: discord.js change role permissions 
Javascript :: javascript remove junk element from array 
Javascript :: country name based on browser 
Javascript :: how to make gamemaker games in javascript 
Javascript :: modal nodejs 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =