-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Typescript | ||
|
||
boardgame.io includes type definitions for Typescript. | ||
|
||
Basic boardgame.io game: | ||
|
||
```typescript | ||
// Game.tsx | ||
import { Game } from 'boardgame.io'; | ||
|
||
export interface MyGameState { | ||
// aka 'G', your game's state | ||
} | ||
|
||
export const MyGame: Game<MyGameState> = { | ||
// ... | ||
} | ||
``` | ||
|
||
## React | ||
|
||
React components must include boardgame.io-specific properties, so extend your props from `BoardProps`: | ||
|
||
```typescript | ||
// Board.tsx | ||
import { BoardProps } from 'boardgame.io/react'; | ||
|
||
interface MyGameProps extends BoardProps { | ||
// Custom properties for your component | ||
} | ||
|
||
export class MyGameBoard extends React.Component<MyGameProps> { | ||
// Your game board | ||
} | ||
``` | ||
|
||
Read more about [Client](api/Client.md) in the reference. No special typing should be required. | ||
|
||
```typescript | ||
// App.tsx | ||
import { Client } from 'boardgame.io/react'; | ||
|
||
import { MyGame } from './Game'; | ||
import { MyGameBoard } from './Board'; | ||
|
||
const App = Client({ | ||
game: MyGame, | ||
board: MyGameBoard, | ||
}); | ||
export default App; | ||
``` |