Created
August 22, 2020 02:37
-
-
Save diego-miranda-ng/736bc880e20e4535f86593ee0c8caada to your computer and use it in GitHub Desktop.
Exemplo da utilização de um hook personalizado para obter a largura da janela.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.js | |
import React, { useState, useEffect } from "react"; | |
import useWindowWidth from "./useWindowWidth"; | |
export default App = (props) => { | |
const [isMobile, setIsMobile] = useState(false); | |
const width = useWindowWidth(); | |
useEffect(() => { | |
setIsMobile(width <= 500); | |
}, [width]); | |
return <span>{isMobile ? "MOBILE" : "DESKTOP"}</span>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment