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

166
Visualizações
Next.js redux useSelector causes html mismatch

I'm using Next.js to create a React app, and I'm using redux with redux-toolkit for state management.

I'm seeing an error in the console stating:
Warning: Did not expect server HTML to contain a <button> in <div>.

I've seen this before, but I'm unsure why this is happening in this particular case.
Here is a simplified version of the component which has this issue:

const TopNav = (): JSX.Element => {
    const user = useSelector(selectAuthUser);

    return (
        <>
            <div>{!user && <LoginNavButton />}</div>
        </>
    );
};

Here is a workaround I've come up with, but I'm not sure why I have to do this:

const TopNav = (): JSX.Element => {
    const user = useSelector(selectAuthUser);
    const [showButton, setShowButton] = useState<boolean>(false);

    useEffect(() => {
        if (!!user) setShowButton(true);
    }, [user]);

    return (
        <>
            <div>{showButton && <LoginNavButton />}</div>
        </>
    );
};

Can anyone explain why the basic usage of useSelector() and referring to state is causing this issue? I'm assuming it's because the server doesn't have access to state, etc. however it seems like a pain to have to work around it like this for basic functionality. Hence, I feel like I'm approaching it incorrectly :)

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