Closed isofarro closed 12 months ago
Hey, thanks so much for opening this PR :)
This is quite a nice approach, but I'm wondering if it's cleaner to expose the api through forwardRef
and useimperativehandle
?
that way we can more easily expose other control methods to the parent, maybe we can even build a few helpers on top of the exposed api to make controlling the chess board easier
Closing in preference for #16 which uses forwardRef and useImperativeHandler.
The current React component doesn't expose the Chessground API in it's interface, which makes it difficult to interact directly with the board from other components.
I've surfaced the API in a callback props called
onApiReady
. This makes the Chessground API available to calling code, and allows interactions like making a move on the board, resetting the board to a new position, and adding arrows. API interface documentation here: https://github.com/lichess-org/chessground/blob/master/src/api.tsSample code demonstrating its use: