Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Latest commit

 

History

History
28 lines (24 loc) · 729 Bytes

use-shuffle.hook.md

File metadata and controls

28 lines (24 loc) · 729 Bytes

useShuffle

This React hook propose an implementation of the shuffle algo.
Wrapped in a useState hook, you can keep in sync your shuffled input with your React component's lifecycles.

How to use it?

import { useShuffle } from '@sugardarius/react-use-algos';

export function Shuffle() {
    const { list, shuffle } = useShuffle([2, 4, 6, 8]);

    return (
        <div>
            <button
                onClick={() => {
                    shuffle();
                }}
            >
                Shuffle it!
            </button>
            <pre>
                {JSON.stringify(list, null, 2)}
            </pre>
        </div>
    );
}