react-random-reveal icon indicating copy to clipboard operation
react-random-reveal copied to clipboard

Not working with Next.js version 13.5.2 React 18.2.0 Hydration

Open andresvpineros opened this issue 2 years ago • 1 comments

While adding the component inside an client component, I get these errors related with next hydration:

Warning: Text content did not match. Server: "s" Client: "x" Warning: An error occurred during hydration. The server HTML was replaced with client content in <#document>. Uncaught Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.

andresvpineros avatar Oct 21 '23 05:10 andresvpineros

You need to check if client rendering is being used:

"use client";
import { RandomReveal } from "react-random-reveal";
import { useEffect, useState } from "react";

const Test = () => {
  const [isClient, setIsClient] = useState(false);

  useEffect(() => {
    setIsClient(true);
  }, []);
  return (
            <span>
              {isClient ? (
                <RandomReveal
                  isPlaying
                  duration={5}
                  characters="?????"
                  updateInterval={0.1}
                  characterSet={["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]}
                />
              ) : (
                "?????"
              )}
            </span>
  );
};

export default Test;

jmne avatar Oct 23 '23 13:10 jmne

Thanks correct! Thanks @jmne

vydimitrov avatar Jul 17 '24 10:07 vydimitrov