Skip to content

Instantly share code, notes, and snippets.

@diego-miranda-ng
Created August 22, 2020 02:37
Show Gist options
  • Save diego-miranda-ng/736bc880e20e4535f86593ee0c8caada to your computer and use it in GitHub Desktop.
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.
// 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