Skip to content

Commit 0db54ec

Browse files
authored
Merge pull request #13 from cjpete/update_readme
Update readme
2 parents da4f780 + 7f0b623 commit 0db54ec

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,50 @@ npm install --save react-toggle-switch
1212
## Usage
1313

1414
```javascript
15-
import React from 'react';
15+
import React, {Component} from 'react';
1616
import {render} from 'react-dom';
1717
import Switch from 'react-toggle-switch'
1818

19-
export default class MyComponent extends React.Component {
19+
class MyComponent extends Component {
20+
21+
constructor(props) {
22+
super(props);
23+
this.state = {
24+
switched: false
25+
};
26+
}
27+
28+
toggleSwitch = () => {
29+
this.setState(prevState => {
30+
return {
31+
switched: !prevState.switched
32+
};
33+
});
34+
};
35+
2036
render() {
2137
return (
2238
<div>
23-
<Switch onClick={() => this.setState({prop: !this.state.prop})}/>
24-
<Switch onClick={this.toggle}>
39+
{/* Basic Switch */}
40+
<Switch onClick={this.toggleSwitch}/>
41+
42+
{/* With children */}
43+
<Switch onClick={this.toggleSwitch}>
2544
<i class="some-icon"/>
2645
</Switch>
46+
47+
{/* Disabled */}
2748
<Switch enabled={false}/>
49+
50+
{/* Custom classnames */}
2851
<Switch className='other-class'/>
2952
</div>
3053
);
3154
}
55+
3256
}
57+
58+
export default MyComponent;
3359
```
3460

3561
### Props
@@ -44,4 +70,4 @@ clicking on it. Default is `false`.
4470

4571
```css
4672
@import "node_modules/react-toggle-switch/dist/css/switch.min.css"
47-
```
73+
```

0 commit comments

Comments
 (0)