Fetching contributors…
Cannot retrieve contributors at this time
82 lines (52 sloc) 1.15 KB


Allows you to toggle the state of a boolean.


import {Toggle} from 'libreact/lib/Toggle';

<Toggle>{({on, toggle}) =>
  <div onClick={toggle}>{on ? 'ON' : 'OFF'}</div>



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';

class MyComp extends Component {


Specify different prop name

class MyComp extends Component {


or merge the the whole object into props

class MyComp extends Component {