Socket
Socket
Sign inDemoInstall

nuke-switch

Package Overview
Dependencies
1
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuke-switch


Version published
Maintainers
3
Created

Readme

Source

Switch

  • category: Components
  • chinese: 开关
  • type: 基本

何时使用

Switch 是状态切换的开关按钮组件。

API

属性说明类型默认值
disabled开关是否可交互booleantrue
checked开启或关闭(受控用法,需与 onValueChange 配合使用)booleanfalse
defaultChecked默认是否选中(非受控用法)booleanfalse
onValueChangeSwitch 改变时调用此函数function(value)

受控用法与非受控用法

所有的输入、交互类组件都有受控用法和非受控用法

  • 受控用法: 组件状态受到外部传入的 props 影响,外部 props 改变,组件才改变,如下 demo :
constructor() {
    super();
    this.state = {
        checked: true
    }
}
change = (value) => {
    this.setState({
        checked:!value
    });
}
//...
render(){
    return (<Switch checked={this.state.checked} onValueChange={this.change}/>)
}
  • 非受控用法: 组件自身自由改变,并通过事件通知外部改变成了什么。如下 demo :
change = (value) => {
    console.log('switch 改变成了:',value);
}
//...
render(){
    return (<Switch defaultChecked={true} onValueChange={this.change}/>)
}

Keywords

FAQs

Last updated on 03 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc