<Toggle>
Allows you to toggle the state of a boolean.
Usage
import {Toggle} from 'libreact/lib/Toggle';
<Toggle>{({on, toggle}) =>
<div onClick={toggle}>{on ? 'ON' : 'OFF'}</div>
}</Toggle>
Props
Signature
interface IToggleProps {
init?: boolean;
}
, where
init
- optional, boolean, initial state of the toggle.
withToggle()
HOC
HOC that merges toggle
prop into enhanced component's props.
import {withToggle} from 'libreact/lib/Toggle';
const MyCompWithToggle = withToggle(MyComp);
You can overwrite the injected prop name
const MyCompWithToggle = withToggle(MyComp, 'foobar');
Or simply merge the whole object into your props
const MyCompWithToggle = withToggle(MyComp, '');
@withToggle
decorator
React stateful component decorator that adds toggle
prop.
import {withToggle} from 'libreact/lib/Toggle';
@withToggle
class MyComp extends Component {
}
Specify different prop name
@withToggle('foobar')
class MyComp extends Component {
}
or merge the the whole object into props
@withToggle('')
class MyComp extends Component {
}