Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!