2.0.2 • Published 4 years ago

toggle-democracy v2.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Toggle Democracy

npm version

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

StateDescription
state.pairsObject of objects, where each value is a pair object with props id, firstValue, secondValue and selected.
state.leaderThe currently selected leader among all options.
api.updatePairFunction to update chosen status for a pair, called as updatePair(id, selected)
2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago