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

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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