davidhu2000 / react-spinners

A collection of loading spinner components for react
https://www.davidhu.io/react-spinners
MIT License
3k stars 260 forks source link

NextJS 13 doesn't render SSR #565

Closed allenchuang closed 4 months ago

allenchuang commented 1 year ago

While experimenting with NextJS 13, and playing around with React <Suspense/> I realized that the animation for all react-spinners components are not working.

<Suspense fallback={<BarLoader color="#36d7b7" />}>
    <SSRLoadedComponent />
</Suspense>
JDuqn commented 4 months ago

For now I just force all my loaders to be client components with a fallback for server side :

"use client"

import React, { useEffect, useState } from "react"
import { ClipLoader } from "react-spinners"

export const Loader = ({ size }: { size: number }) => {
  const [isClient, setIsClient] = useState(false)

  useEffect(() => {
    setIsClient(true)
  }, [])

  return (
    <React.Fragment>
      {isClient ? (
        <ClipLoader ... />
      ) : (
        <ServerSideSpinner ... />
      )}
    </React.Fragment>
  )
}

Not sure this is a good approach, but it might help someone.

davidhu2000 commented 4 months ago

duplicate of #576