Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eyaleizenberg/b4c806b35274782026943625bb4a6289 to your computer and use it in GitHub Desktop.
Save eyaleizenberg/b4c806b35274782026943625bb4a6289 to your computer and use it in GitHub Desktop.
interface IProps {
superhero: string;
}
interface IState {
health: number;
}
const getInitialHealth = (props: IProps) => props.superhero === "Spiderman" ? 0 : 100;
export class MyComponent extends React.PureComponent<IProps, IState> {
readonly state = { health: getInitialHealth(this.props) };
render() {
return <span>{`${this.props.superhero} health is: ${this.state.health}`}</span>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment