toggle-democracy
v2.0.2
Published
React hook for converting a list of options to a democracy through toggle pairs.
Downloads
3
Readme
Toggle Democracy
The totally useless package that grants you a React hook for converting a list of options to a democracy through pairs of options. Give the hook an initial state of options and receive the combinations of pairs running up for leadership, alongside the currently chosen leader and an api function to update chosen status between pairs of options.
npm install toggle-democracy
Usage
import React from 'react';
import useToggleDemocracy from 'toggle-democracy';
const ExampleComponent = () => {
const options = ['Foo', 'Bar', 'Baz'];
const [state, api] = useToggleDemocracy(options);
return (
<div>Use your imagination!</div>
)
}
Documentation
| State | Description |
|:---|:---|
| state.pairs
| Object of objects, where each value is a pair object with props id
, firstValue
, secondValue
and selected
. |
| state.leader
| The currently selected leader among all options. |
| api.updatePair
| Function to update chosen status for a pair, called as updatePair(id, selected)
|