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

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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