Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Important note regarding SSR for @bsmnt/drop #21

Closed
alii opened this issue Oct 16, 2022 · 1 comment · Fixed by #25
Closed

fix: Important note regarding SSR for @bsmnt/drop #21

alii opened this issue Oct 16, 2022 · 1 comment · Fixed by #25

Comments

@alii
Copy link

alii commented Oct 16, 2022

The readme specifies that rendering the time on the server is difficult, or that we should render a different time until we are on the client. React says that we can (very carefully) still render different values on the server if the child is strictly only a text node.

From the React docs (https://reactjs.org/docs/react-dom.html):

If a single element’s attribute or text content is unavoidably different between the server and the client (for example, a timestamp), you may silence the warning by adding suppressHydrationWarning={true} to the element. It only works one level deep, and is intended to be an escape hatch. Don’t overuse it. Unless it’s text content, React still won’t attempt to patch it up, so it may remain inconsistent until future updates.

Maybe it would be cool to include this in the Readme. E.g:

import { useEffect, useState } from "react";
import { useCountdownStore } from "@bsmnt/drop";

const Countdown = () => {
  const humanTimeRemaining = useCountdownStore()(
    state => state.humanTimeRemaining,
  );

  return (
    <div>
      <h1>Countdown</h1>
      <ul>
        <li suppressHydrationWarning>Days: {humanTimeRemaining.days}</li>
        <li suppressHydrationWarning>Hours: {humanTimeRemaining.hours}</li>
        <li suppressHydrationWarning>Minutes: {humanTimeRemaining.minutes}</li>
        <li suppressHydrationWarning>Seconds: {humanTimeRemaining.seconds}</li>
      </ul>
    </div>
  );
};
@julianbenegas
Copy link
Contributor

great idea. will work on suggesting this in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants