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

164
Views
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
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!