shubhanus / otp-input-react

React simple otp input with react hooks
MIT License
59 stars 85 forks source link

window is not defined with Next.js #54

Closed webdiego closed 2 years ago

webdiego commented 2 years ago

I get "window is not defined" with Next.js

webdiego commented 2 years ago

This is a possible solution:

import dynamic from 'next/dynamic';

const OTPInput = dynamic(() => import('otp-input-react'), { ssr: false });

vennhost commented 2 years ago

@webdiego After using your solution I am getting another error: Property 'value' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'

What's the work-around on this?

<OTPInput value={OTP} onChange={setOTP} autoFocus OTPLength={4} otpType="number" disabled={false} secure />

webdiego commented 2 years ago

It could be a typescript error, I'm sorry but I can't help you because I didn't use TS, have u install the types of the library?🤔

zaykhere commented 2 years ago

I'm also getting this error when using with razzle. Any idea why this is happening?

zaykhere commented 1 year ago

@webdiego How did you solve this issue?

zaykhere commented 1 year ago

nvm I solved it by importing it like this:

const { ResendOTP } = dynamic(() => import('otp-input-react'), {ssr: false})

webdiego commented 1 year ago

This is a possible solution:

import dynamic from 'next/dynamic';

const OTPInput = dynamic(() => import('otp-input-react'), { ssr: false });

Yes as I said a long time ago :)