mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
Fix graphql and other things
This commit is contained in:
16
src-web/hooks/useUniqueKey.ts
Normal file
16
src-web/hooks/useUniqueKey.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
export function useUniqueKey(len = 10): { key: string; regenerate: () => void } {
|
||||
const [key, setKey] = useState<string>(() => generate(len));
|
||||
return { key, regenerate: () => setKey(generate(len)) };
|
||||
}
|
||||
|
||||
const CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
|
||||
function generate(len: number): string {
|
||||
const chars = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
chars.push(CHARS[Math.floor(Math.random() * CHARS.length)]);
|
||||
}
|
||||
return chars.join('');
|
||||
}
|
||||
Reference in New Issue
Block a user