willb335 / chessboardjsx

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

Adding onStartDrag callback #74

Open dfish13 opened 2 years ago

dfish13 commented 2 years ago

I thought it would be useful to add an onStartDrag(square) prop that is called whenever the user initiates a drag for a piece. For example it would help with highlighting the available moves when a user grabs a piece. And maybe an onStopDrag too!

I tried to use allowDrag to achieve this effect but for some reason allowDrag is called many times after a piece is dropped. When I added logic to compute available moves and change squareStyles for those squares in the allowDrag function it ended up calling allowDrag even more times and crashing the component. So I guess allowDrag was not designed to be used this way and I don't really understand why it gets called so many times.

I would be happy to work on this issue since I use this library on a personal project : )

Clariity commented 2 years ago

react-chessboard (that was made because this library is no longer maintained) has onPieceDragBegin and onPieceDragEnd

dfish13 commented 2 years ago

@Clariity Excellent! I will probably migrate my project over to use react-chessboard then.