diff --git a/src/components/List/List.tsx b/src/components/List/List.tsx index 83ad562..f62f783 100644 --- a/src/components/List/List.tsx +++ b/src/components/List/List.tsx @@ -3,7 +3,7 @@ import { Link } from "react-router-dom"; interface ListProps { className: string; - itemsList: { value: string; name: string }[]; + itemsList: { value: string; name: string; phoneNumber?: string }[]; } const List = (props: ListProps) => { @@ -11,11 +11,18 @@ const List = (props: ListProps) => { return ( ); }; diff --git a/src/contexts/WidthContext.tsx b/src/contexts/WidthContext.tsx new file mode 100644 index 0000000..14b2fed --- /dev/null +++ b/src/contexts/WidthContext.tsx @@ -0,0 +1,36 @@ +import { createContext, useState, useEffect } from "react"; + +interface WidthContextData { + width: number; + isMobile: boolean; +} + +interface Props { + children: React.ReactNode; +} + +export const WidthContext = createContext({} as WidthContextData); + +export const WidthProvider: React.FC = ({ children }) => { + const [width, setWidth] = useState(window.innerWidth); + const [isMobile, setIsMobile] = useState(width <= 1024); + + const updateWidth = () => { + setWidth(window.innerWidth); + console.log("atualizou width"); + }; + + useEffect(() => { + window.addEventListener("resize", updateWidth); + }, []); + + useEffect(() => { + width <= 1024 ? setIsMobile(true) : setIsMobile(false); + }, [width]); + + return ( + + {children} + + ); +}; diff --git a/src/index.tsx b/src/index.tsx index aa1a139..f7e1235 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,14 +5,17 @@ import Institucional from "./pages/Institucional"; import "./global.scss"; import { ModalProvider } from "./contexts/ModalContext"; +import { WidthProvider } from "./contexts/WidthContext"; const root = ReactDOM.createRoot( document.getElementById("root") as HTMLElement ); root.render( - - - + + + + + );