<Map>

Gives you a map as a state.

Usage

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

<Map init={{c: 'd'}}>{({get, set, remove}) =>
  <div>
    <div>a: {get('a')}</div>
    <pre style={{fontFamily: 'monospace'}}>{JSON.stringify(get())}</pre>
    <button onClick={() => set('a', 'b')}>set('a', 'b')</button>
    <button onClick={() => remove('a')}>remove('a')</button>
  </div>
}</Map>

Props

Signature

interface IMapProps {
  init?: {[key: string]: any};
}

, where

  • init - optional, map of initial values.

withMap() HOC

HOC that merges map prop into enhanced component's props.

import {withMap} from 'libreact/lib/Map';

const MyCompWithMap = withMap(MyComp);

You can overwrite the injected prop name

const MyCompWithMap = withMap(MyComp, 'foobar');

Or simply merge the whole object into your props

const MyCompWithMap = withMap(MyComp, '');

Set default value

const MyCompWithMap = withMap(MyComp, '', {foo: 'bar'});

@withMap decorator

React stateful component decorator that adds map prop.

import {withMap} from 'libreact/lib/Map';

@withMap
class MyComp extends Component {

}

Specify different prop name

@withMap('foobar')
class MyComp extends Component {

}

or merge the the whole object into props

@withMap('')
class MyComp extends Component {

}

set starting value

@withMap('', {foo: 'bar'})
class MyComp extends Component {

}

results matching ""

    No results matching ""