Skip to content

Instantly share code, notes, and snippets.

@iansmith
Last active March 24, 2021 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iansmith/38b3ec61811aa10f1d0d3e30266a1e7a to your computer and use it in GitHub Desktop.
Save iansmith/38b3ec61811aa10f1d0d3e30266a1e7a to your computer and use it in GitHub Desktop.
from evalvite article, definition of component
// file: example1/importantcheckbox.ts
// imports omitted
export default class ImportantCheckBox extends React.Component<
localProps,
localState
> {
msg = "this is my message, there are many like it but this one is mine";
constructor(props: localProps) {
super(props);
ev.bindModelToComponent<ImportantCheckBoxModel>(this.props.model, this);
this.state = { important: false };
}
change = (e: React.FormEvent<HTMLInputElement>) => {
const { important } = this.props.model;
important.set(!important.get());
};
render(): React.ReactNode {
const { important } = this.state; // USE STATE!
let content = <span className="text-muted">{this.msg}</span>;
if (important) {
content = <span className="font-weight-bold">{this.msg}</span>;
}
let box = <input type="checkbox" onChange={this.change} />;
return (
<Row>
<Col className="col-1 text-right">{box}</Col>
<Col className="col-4">{content}</Col>
</Row>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment