diff options
| author | haishanh <[email protected]> | 2018-11-05 18:32:16 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2018-11-06 22:37:21 +0800 |
| commit | 91ecdaa5dd1a65ff0ae944896945c0fe4bc23574 (patch) | |
| tree | 9f7f476672fae91eca5df9e0ae021b45df950679 /src/components/Switch.js | |
| parent | 1adaedcbc551f6beee4e9e0b9fbd94197ebdffe5 (diff) | |
update: convert more components to function ones
includes Input, Config, SideBard.
also removed react-redux Provider
Diffstat (limited to 'src/components/Switch.js')
| -rw-r--r-- | src/components/Switch.js | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/components/Switch.js b/src/components/Switch.js index 5a2119a..f956b6d 100644 --- a/src/components/Switch.js +++ b/src/components/Switch.js @@ -1,35 +1,27 @@ -import React, { Component } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import s0 from 'c/Switch.module.scss'; +const noop = () => {}; -class Switch extends Component { - static propTypes = { - checked: PropTypes.bool, - onChange: PropTypes.func, - name: PropTypes.string - }; - - static defaultProps = { - checked: false, - name: '', - onChange: () => {} - }; - - render() { - const { checked, onChange, name } = this.props; - return ( - <div> - <input - type="checkbox" - name={name} - checked={checked} - className={s0.switch} - onChange={onChange} - /> - </div> - ); - } +function Switch({ checked = false, onChange = noop, name = '' }) { + return ( + <div> + <input + type="checkbox" + name={name} + checked={checked} + className={s0.switch} + onChange={onChange} + /> + </div> + ); } -export default Switch; +Switch.propTypes = { + checked: PropTypes.bool, + onChange: PropTypes.func, + name: PropTypes.string +}; + +export default React.memo(Switch); |
