Skip to content

SSR hydration warning #17

Description

@thorsten-stripe

Hey, this module is great and we use it over at https://github.com/dayhaysoos/use-shopping-cart :) ❤️

We've had some folks run into this issue (dayhaysoos/use-shopping-cart#122) which seems to be a hydration warning because the server-side rendered value differs from the value on the client.

Have you seen that before by any chance? I did some digging, and the general recommendation is to use the same initial state as on the server, and then update it in a useEffect hook, but I'm not sure if that's possible within a custom hook 🤔

Reproduction steps

I've set up an environment to reproduce: https://codesandbox.io/s/autumn-grass-vhu4e?expanddevtools=1&fontsize=14&hidenavigation=1&theme=dark

  1. Navigate to CodeSandbox
  2. Switch to the Console tab (Second tab next to Terminal in the bottom right dev tools)
  3. Click the + button a couple times so counter is !== 0
  4. Click preview reload button
  5. See warning in console

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions