Skip to content

Commit

Permalink
fix npe better
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Slatcher committed Oct 19, 2018
1 parent f14c982 commit ea01a97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions projects/app/src/pages/GamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ export class GamePage extends React.PureComponent<GamePageProps, GamePageState>
if (this.state.loading || !this.state.leaguePlayers || !game || game.players == null) {
return <div className="th-game">Loading...</div>;
}
const handlePlayerChanged = (index: number) => (player: IPlayer | null) => {
const handlePlayerChanged = (index: number) => (player: IPlayer | undefined) => {
const newGame = {
...game,
players: game.players!.slice(),
};
newGame.players[index] = player;
newGame.players[index] = player || null;
this.setState({ game: newGame });
};
const choosers: JSX.Element[] = [];
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/components/PlayerChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from "react";
export interface PlayerChooserProps {
players: IPlayer[];
selectedPlayer: IPlayer | undefined | null;
onPlayerChanged(player: IPlayer | null): void;
onPlayerChanged(player: IPlayer | undefined): void;
}

export class PlayerChooser extends React.PureComponent<PlayerChooserProps, {}> {
Expand All @@ -27,6 +27,6 @@ export class PlayerChooser extends React.PureComponent<PlayerChooserProps, {}> {
private handlePlayerChooserChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const playerId = event.target.value;
const player = this.props.players.find(p => p.id.toString() === playerId);
this.props.onPlayerChanged(playerId === "" || !player ? null : player);
this.props.onPlayerChanged(playerId === "" ? undefined : player);
};
}

0 comments on commit ea01a97

Please sign in to comment.