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.
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>
);
}