@dhiwise/react-switch
v1.0.2
Published
A simple switch component for React.
Downloads
348
Maintainers
Readme
@dhiwise/react-switch
A simple switch component.
Made with create-react-library
Install
npm install --save @dhiwise/react-switch
Usage
import React, { Component } from 'react'
import Switch from '@dhiwise/react-switch'
import '@dhiwise/react-switch/dist/index.css'
const BasicExample = () => {
const [checked, setChecked] = useState(false);
const handleChange = nextChecked => {
setChecked(nextChecked);
};
return (
<div className="example">
<h2>Simple usage</h2>
<label>
<span>Switch with default style</span>
<Switch
onChange={handleChange}
checked={checked}
className="react-switch"
/>
</label>
<p>
The switch is <span>{checked ? "on" : "off"}</span>.
</p>
</div>
);
};