Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react check if mobile or desktop

import React, {useEffect, useState} from "react";

const useCheckMobileScreen = () => {
    const [width, setWidth] = useState(window.innerWidth);
    const handleWindowSizeChange = () => {
            setWidth(window.innerWidth);
    }

    useEffect(() => {
        window.addEventListener('resize', handleWindowSizeChange);
        return () => {
            window.removeEventListener('resize', handleWindowSizeChange);
        }
    }, []);

    return (width <= 768);
}

export default useCheckMobileScreen
Comment

react show if mobile or browser

import {BrowserView, MobileView} from 'react-device-detect';

const MyComponent = () => {
    return (
        <>
            <BrowserView>
                <h1>This is rendered only in browser</h1>
            </BrowserView>
            <MobileView>
                <h1>This is rendered only on mobile</h1>
            </MobileView>
        </>
    );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: Auto scroll to bottom of div angular 
Javascript :: javascript array flat 
Javascript :: install aos angular 10 
Javascript :: jquery window trigger resize 
Javascript :: open modal js 
Javascript :: find whitespace in string js 
Javascript :: gradlew command not found react native 
Javascript :: react not getting img by src 
Javascript :: jquery checkbox unchecked 
Javascript :: ref css in jsp 
Javascript :: get full month from date javascript 
Javascript :: alphabet only in jquery 
Javascript :: what is the meanof using next in nodejs 
Javascript :: set min date field to current date 
Javascript :: javascript reverse loop 
Javascript :: dropzone get response 
Javascript :: lodash angular 9 
Javascript :: check if any property of object is null javascript 
Javascript :: toggle class javascript stack overflow 
Javascript :: javascript iterate over divs 
Javascript :: substring javscript 
Javascript :: ngmodel angular 
Javascript :: loop in object javascript 
Javascript :: nodejs file exists 
Javascript :: js conditional object 
Javascript :: jquery forEach is not a function 
Javascript :: javascript read server file 
Javascript :: how to get multiple checkbox value in jquery 
Javascript :: javascript element distance from top 
Javascript :: linked list javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =