Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Convert to class component
  • Loading branch information
rickhanlonii committed Mar 18, 2018
commit b0d28888154aec2e05cfb3249520b9a2a1a7c12d
25 changes: 13 additions & 12 deletions examples/typescript/CheckboxWithLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
/// <reference path="./typings/react/react.d.ts" />

import * as React from 'react'
import * as createReactClass from 'create-react-class';

interface CheckboxWithLabelProps extends React.Props<any> {
interface CheckboxWithLabelProps {
labelOff: string;
labelOn: string;
}

var CheckboxWithLabel = createReactClass<CheckboxWithLabelProps, any>( {
getInitialState: function() {
return {isChecked: false}
},
onChange: function() {
this.setState({isChecked: !this.state.isChecked});
},
interface CheckboxWithLabelState {
isChecked: boolean;
}

class CheckboxWithLabel extends React.Component<CheckboxWithLabelProps, CheckboxWithLabelState> {
constructor(props: CheckboxWithLabelProps) {
super(props);
this.state = {isChecked: false};
}

render: function() {
render() {
return (
<label>
<input
type="checkbox"
checked={this.state.isChecked}
onChange={this.onChange}
onChange={() => this.setState(current => ({isChecked: !current.isChecked}))}
/>
{this.state.isChecked ? this.props.labelOn : this.props.labelOff}
</label>
);
}
});
}

export = CheckboxWithLabel;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"browserify": "^16.1.0",
"chalk": "^2.0.1",
"codecov": "^3.0.0",
"create-react-class": "^15.6.3",
"cross-spawn": "^6.0.4",
"debug": "^3.0.1",
"enzyme": "^3.3.0",
Expand Down
Loading