I've been looking a bit at chessboardjs (https://chessboardjs.com/) as a way to get some practice with some React coding. However, I haven't been able to get the simple example of just showing the board in my app working. the documentation says to use <div id="board" style={{width: 400}}/>
in the HTML, and var board = ChessBoard('board', 'start');
to get startet. However, ChessBoard('board', 'start');
gives me an "object not a function" compilation error. I've tried fiddling a lot of different things (such as adding the anonymous function with the jquery tag), but I seem to be doing something wrong. I hope someone can spot it.
My React app (using typescript) has the standard App component, which just has a ChessComponent, which looks the following way:
import * as React from 'react';
import {ChessBoard} from 'chessboardjs';
import * as $ from 'jquery';
class ChessComponent extends React.Component {
constructor(props:any) {
super(props);
}
componentDidMount() {
$(function() {
var board = ChessBoard('board', 'start');
});
}
render() {
return (
<div id="board" style={{width: 400}}/>
)
}
}
export default ChessComponent
and my package.json looks like this:
{
"name": "chess-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"chess": "^0.4.1",
"chessboardjs": "0.0.1",
"jquery": "^3.4.0",
"react": "^16.5.2",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.5.2",
"react-scripts-ts": "3.1.0",
"tslint": "^5.11.0",
"tslint-react": "^3.6.0"
},
"scripts": {
"start": "react-scripts-ts start --noUnusedParameters=false",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject"
},
"devDependencies": {
"@types/chessboardjs": "^0.3.1",
"@types/jest": "^23.3.2",
"@types/jquery": "^3.3.29",
"@types/node": "^10.11.3",
"@types/react": "^16.4.14",
"@types/react-dom": "^16.0.8",
"typescript": "^3.1.1"
}
}