Как вывести ключ, созданные функцией?
Вот код:
const [letters, setLetters] = useState('abcdefghijklmnopqrstuvwxyz0123456789')
const [key, setKey] = useState('');
const randomKeyGenerator = () => {
let word = '';
for (let i = 0; i < 16; i++) {
word += letters.charAt(Math.floor(Math.random() * letters.length));
}
const test = word.substring(0, 5) + '-' + word.substring(5, 10) + '-' + word.substring(10, 15);
setKey(test.toUpperCase());
};
return (
<Panel>
<Text>Здесь будет ключ:</Text>
<Button onClick={randomKeyGenerator}>тыык</Button>
</Panel>
);
Источник: Stack Overflow на русском