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

153
Visualizações
React dev tools highlighting components that doesn't update

I'm testing the use-context-selector lib to prevent unnecessary rendering in react ContextApi. I create this simple application:

export const HomeProvider = (props: PropsWithChildren<{}>) => {
  const [x, setX] = React.useState(0);

  const [y, setY] = React.useState(0);

  return (
    <HomeContext.Provider value={{ x, setX, y, setY }}>
      {props.children}
    </HomeContext.Provider>
  );
};

export const HomeModule = () => {
  return (
    <HomeProvider>
      <CounterScreen></CounterScreen>
      <br />
      <br />
      <MessageScreen></MessageScreen>
    </HomeProvider>
  );
};

The child components are:


export const MessageScreen = () => {
  const x = useContextSelector(HomeContext, (context) => context.x);

  const setX = useContextSelector(HomeContext, (context) => context.setX);

  return (
    <>
      <h1>Teste X</h1>
      {x} <button onClick={() => setX(x + 1)}>X</button>
    </>
  );
};

export const MessageScreen = () => {
  const x = useContextSelector(HomeContext, (context) => context.x);

  const setX = useContextSelector(HomeContext, (context) => context.setX);

  return (
    <>
      <h1>Teste Y</h1>
      {y} <button onClick={() => setY(y + 1)}>X</button>
    </>
  );
};

The result, when I click in any one of those button is that indeed the child components doesn't rerender:

https://i.stack.imgur.com/9adCh.png

But, when I use the option: Highlight updates when components render in settings, all components on the screen is highlighted.

So, am i missing something or i'm right about the child components not rerendering ?? I saw other videos on youtube that show that when using this lib, the component that didn't render was not highlighted.

about 4 years ago · Juan Pablo Isaza
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