Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active September 6, 2018 23:50
Show Gist options
  • Save ajcrites/0680d4766798089bfa58dd1b0c2c33aa to your computer and use it in GitHub Desktop.
Save ajcrites/0680d4766798089bfa58dd1b0c2c33aa to your computer and use it in GitHub Desktop.
// Example
export class ConstructorComponent extends React.Component<{ start: number }, { count: number }> {
// React Components takes `props` as a constructor argument. You can set default state here as well.
constructor(props) {
super(props);
this.state = { count: props.start };
this.count = countService.count();
this.positiveCount = this.count.pipe(filter(c => c > 0));
}
}
// Better (imo) Example
import * as React from 'react';
export class NoConstructorComponent extends React.Component<{ start: number }, { count: number }> {
state = { count: this.props.start };
count = countService.count();
positiveCount = this.count.pipe(filter(c => c > 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment