Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuke-switch

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuke-switch

开关

  • 1.0.4
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-68.97%
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 29 Dec 2017

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc