willb335 / chessboardjsx

:black_square_button: Chessboard built for React
https://chessboardjsx.com
MIT License
267 stars 79 forks source link

Next js support? #60

Closed DanielJ06 closed 3 years ago

DanielJ06 commented 3 years ago

I tried to use with next recently, and got the error "window not defined". Any idea how to solve?

willb335 commented 3 years ago

I would add a condition check if (window === undefined) { return null } else {return <Chessboard /> }. Chessboardjsx has a dependency on the window object and when Next is building it does not have access to window. I would also look into other chessboard libs as this one is unmaintained

DanielJ06 commented 3 years ago

Got it. It is a very cool lib, and it is sad that it is no longer maintained, do you have any recommendations for another similar lib?

willb335 commented 3 years ago

Maybe check out this one: https://github.com/ruilisi/react-chessground

DanielJ06 commented 3 years ago

I'll take a look. Thank you very much for your attention

neatshell commented 3 years ago

Hi @DanielJ06 if can help you, I've solved with these 3 lines of code and still using this wonderful library

import dynamic from 'next/dynamic';

const Chessboard = dynamic(() => import('chessboardjsx'), {
  ssr: false  // <- this do the magic ;)
});
marlongerson commented 3 years ago

Hi @DanielJ06 if can help you, I've solved with these 3 lines of code and still using this wonderful library

import dynamic from 'next/dynamic';

const Chessboard = dynamic(() => import('chessboardjsx'), {
  ssr: false  // <- this do the magic ;)
});

Thank you so much!

withrvr commented 2 years ago

Hi @DanielJ06 if can help you, I've solved with these 3 lines of code and still using this wonderful library

import dynamic from 'next/dynamic';

const Chessboard = dynamic(() => import('chessboardjsx'), {
  ssr: false  // <- this do the magic ;)
});

thx so much bro .... you are god