Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
how can I handle media query in react js

I have a div with display:flex but I want in mobile size (actually in special media query) change display to block

 <Col sm={8}>
  <div className="d-flex">
     <Col md={4} xs={12} className="has-float-label p-0">
     <Label>years</Label>
     <Select
     components={{ Input: CustomSelectInput }}
     className="react-select w-full"
     classNamePrefix="react-select"
     value={selectedDate.year}
     onChange={(value) => setSelectedDate({ ...selectedDate, year: value })}
     options={years}
     placeholder=""
     />
     </Col>     
   </div>
</Col>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could create a custom hook for that so you can reuse it as needed, let's call it useScreenSize for example:

const [screenSize, setScreenSize] = useState(undefined);

const handleResize = () => setScreenSize(window.innerWidth);

useEffect(() => {
    window.addEventListener("resize", handleResize);
    handleResize();

    return () => window.removeEventListener("resize", handleResize)
}, [])

return screenSize;

Then in your component(s), you could use the value returned from this hook to specify which classes you want to apply, for example, if the screen's width is let's say 600px (or the breakpoint on which you actually want to change your classes), then you can apply your class based on that.

Let me know if that helps.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda