/* Dependencies */ import React, { useState, useEffect } from 'react' import { View, StyleSheet } from 'react-native' /* Libraries */ import { Button } from 'react-native-paper' /* Types */ type Props = { setRandomPass: React.Dispatch> setText: React.Dispatch> text: string } const PadPassword = ({ setRandomPass, setText, text }: Props) => { /* States */ const [randPass, setRandPass] = useState([]) /* Functions */ const _rand = (maxLimit: number = 10) => { let pas: number[] = [] let rand = 0 while (pas.length !== 10) { rand = Math.random() * maxLimit rand = Math.floor(rand) if (pas.indexOf(rand) === -1) { pas = [...pas, rand] } } setRandPass(pas) setRandomPass(pas) } const _concat = (value: string) => { setText(`${text}${value}`) } /* Hooks */ useEffect(() => { _rand() }, []) return ( ) } const styles = StyleSheet.create({ container: { marginLeft: 5, marginRight: 5, marginTop: 10 }, button: { flex: 1, height: 45, marginRight: 3, marginTop: 3, paddingTop: 7 }, row: { flexDirection: 'row', flexGrow: 1 } }) PadPassword.displayName = 'Pad.Password' export default PadPassword