Git Product home page Git Product logo

Comments (8)

KarsonJo avatar KarsonJo commented on June 5, 2024 4

@SaiRev0 Sorry, I didn't find it, only a workaround.
I tried installing an earlier version (2.4.0) and it seems to not have this problem. But unfortunately this version has the problem of inconsistent random ids generated by client and server.
Recent releases seem to use more browser APIs, so I ended up wrapping it into a client-only component.

// react-chrono-client.ts
"use client"

import type { Chrono as ChronoType } from "react-chrono";
import dynamic from 'next/dynamic'

export const Chrono = dynamic(() => import('react-chrono').then(lib => lib.Chrono), {
  ssr: false,
}) as typeof ChronoType

from react-chrono.

KarsonJo avatar KarsonJo commented on June 5, 2024 1

@swastkk have you tried running the app with the use client directive

Yes, I tried that and it doesn't work. The reason is that nextjs pre-renders client components on server as well. So even if it's marked as use client, chrono will still be rendered on server. Maybe putting window access into useEffect would work?

from react-chrono.

prabhuignoto avatar prabhuignoto commented on June 5, 2024

@swastkk are you running this from a Next JS app or is it a React SPA.

from react-chrono.

swastkk avatar swastkk commented on June 5, 2024

@swastkk are you running this from a Next JS app or is it a React SPA.

I am working on NextJS

from react-chrono.

prabhuignoto avatar prabhuignoto commented on June 5, 2024

@swastkk have you tried running the app with the use client directive

from react-chrono.

SaiRev0 avatar SaiRev0 commented on June 5, 2024

@KarsonJo Hey, so did you find any solution ??

from react-chrono.

Milan-Bhingradiya avatar Milan-Bhingradiya commented on June 5, 2024

@KarsonJo what u did here can u help me to understand ? i want to render chrono component at client side..

from react-chrono.

KarsonJo avatar KarsonJo commented on June 5, 2024

@KarsonJo what u did here can u help me to understand ? i want to render chrono component at client side..

@Milan-Bhingradiya dynamic with ssr: false defines a component that wraps Chrono and turns off server-side rendering. After that, you need to import Chrono from this file (called react-chrono-client.ts in this example) instead. Then you can use it as usual without rendering on server.

from react-chrono.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.