Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
React : Apply Body overflow on specific component

I created a react app using create-react-app. My file structure is like the following :

Index.js
App.css
App.js
-- MyComponent1.js
-- MyComponent2.js

To navigate between the two components I'm using react-router-dom in App.js like this :

<BrowserRouter>
        <Route path='/MyComponent1' exact component={MyComponent1} />
        <Route path='/MyComponent2' exact component={MyComponent2} />
</BrowserRouter>

So both components are using the same App.css style imported in App.js

I want to apply an overflow:hidden to the body when I'm only on Component1 and remove this new class on other components, how to do so ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Found the solution!

All I had to do was using document.body directly on the component to set the styles directly using Hook.

So overflow:visible will be applied on the component mounting, and overflow:hidden on the component unmounting like the following :

      useEffect(() => {
// Applying on mount
        document.body.style.overflow = "hidden";
// Applying on unmount    
        return () => {
          document.body.style.overflow = "visible";
        }
      }, [])
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda