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

130
Views
useEffect doesn't re-render main parent component

useEffect doesn't re-render the main parent component when I change state 'click button' in other component. When I reload page magic heapens. How should I re-render main <App /> component on this event without reloading page?

const ResponsiveAppBar = () => {
const defaultDark = window.matchMedia(
    '(prefers-color-scheme: dark)'
).matches;

let [theme, setTheme] = useLocalStorage(
    'theme',
    defaultDark ? 'dark' : 'light'
);

React.useEffect(() => {
    console.log('theme changed into: ', theme);
    <App />;
}, [theme]);

const switchTheme = () => {
    const newTheme = theme === 'light' ? 'dark' : 'light';
    console.log(newTheme);
    setTheme(newTheme);
};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

What you are looking for is explained here (Context - React).

Basically, you should use React Context to share the state between parent and child components. If a child component wants to change the Theme, you can grab the setTheme hook from the Context and call it as needed.

about 4 years ago · Juan Pablo Isaza Report

0

if you wanna have light and dark mode you have to be able to access the state every where to do that you should learn about react context api or try to learn Redux if you to make a large scale app

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!