Update Toggle.md
This commit is contained in:
@ -2,11 +2,10 @@
|
||||
|
||||
Renders a toggle component.
|
||||
|
||||
The `state` of the component default to `false` and bind the `handleClick` method to the component's context.
|
||||
Initialize `state.isToggleOn` to `false`, bind the `handleClick` method to the component's context.
|
||||
Use an object, `style`, to hold the styles for individual components and their states.
|
||||
Create a method, `handleClick`, which uses `Component.prototype.setState` to change the component's `state` from toggleOn to toggleOff and vice versa.
|
||||
In the `render()` method, destruct `state` and `style` to abbreviate typing, use a `<button>` that alters the component's `state`.
|
||||
Determine the appearance of the content, based on `state.isToggleOn` and apply the appropriate CSS rules from the `style` object.
|
||||
Create a method, `handleClick`, which uses `Component.prototype.setState` to change the component's `state.toggleOn`.
|
||||
In the `render()` method, destructure `state` and `style`, create a `<button>` that alters the component's `state` and determine the appearance of the content based on `state.isToggleOn`, applying the appropriate CSS rules from the `style` object.
|
||||
|
||||
```jsx
|
||||
class Toggle extends React.Component {
|
||||
@ -53,6 +52,6 @@ class Toggle extends React.Component {
|
||||
ReactDOM.render(<Toggle />, document.getElementById('root'));
|
||||
```
|
||||
|
||||
<!-- tags: visual,toggle,state,class -->
|
||||
<!-- tags: visual,state,class -->
|
||||
|
||||
<!-- expertise: 0 -->
|
||||
<!-- expertise: 0 -->
|
||||
|
||||
Reference in New Issue
Block a user