1.0.0 • Published 5 years ago

react-selection-helper v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

react-selection-helper

To install

yarn add react-selection-helper

To use

import SelectableList from 'react-selection-helper'

const toId = ({ id }) => id
const List = ({ items }) =>
  <SelectableList
    ids={items.map(toId)}
    render={({ selectedIds, onSelect }) => 
        items.map(({ id, name }) => {
            const isSelected = selectedIds.includes(id)
            return (<li
                    key={id}
                    onClick={onSelect(id)}
                    className={isSelected ? 'selected' : ''}
                >
                    <input
                        type="checkbox"
                        value={id}
                        checked={isSelected}
                        onClick={onSelect(id)}
                    />
                    {name}
                </li>)
        })
    }
  />
1.0.0

5 years ago