-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove dependency on react chessground
- Loading branch information
1 parent
566675f
commit a230832
Showing
9 changed files
with
3,383 additions
and
13,715 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Chessground as NativeChessground } from "chessground"; | ||
import { Api } from "chessground/api"; | ||
import { Config } from "chessground/config"; | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
interface ChessgroundProps extends Config { | ||
height?: string | number; | ||
width?: string | number; | ||
} | ||
|
||
export function Chessground(props: ChessgroundProps) { | ||
const [api, setApi] = useState<Api | null>(null); | ||
|
||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
if (ref && ref.current && !api) { | ||
const chessgroundApi = NativeChessground(ref.current, props); | ||
setApi(chessgroundApi); | ||
} else if (ref && ref.current && api) { | ||
api.set(props); | ||
} | ||
}, [api, props, ref]); | ||
|
||
useEffect(() => { | ||
api?.set(props); | ||
}, [api, props]); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
height: props.height, | ||
width: props.width, | ||
}} | ||
ref={ref} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.