Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react check if in mobile

const [width, setWidth] = useState<number>(window.innerWidth);

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

const isMobile = width <= 768;
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 :: image preview using js 
Javascript :: react date picker disable past dates 
Javascript :: require is undefined 
Javascript :: find string in array javascript 
Javascript :: javascript document remove 
Javascript :: return random rows sqlite 
Javascript :: javascript dynamicly include another js file 
Javascript :: splidejs pauseOnHover 
Javascript :: expressjs swagger yaml 
Javascript :: joi schema for confirm password 
Javascript :: f string javascript 
Javascript :: cypress have attribute 
Javascript :: efi javascript 
Javascript :: node eventemitter emit error 
Javascript :: react native socket io 
Javascript :: javascript check if date object 
Javascript :: console.time in javascript 
Javascript :: js api call 
Javascript :: node get root directory 
Javascript :: refresh current component angular 
Javascript :: javascript decode uri 
Javascript :: require express 
Javascript :: push-method-in-react-hooks-usestate 
Javascript :: disable eslint 
Javascript :: javascript sort array strings alphabetically 
Javascript :: check if input is a number javascript 
Javascript :: electron main.js template 
Javascript :: js classlist 
Javascript :: nodejs request api 
Javascript :: object in array javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =