useStae with array of strings typescript
const [devices, setDevices] = useState<string[]>([])
useStae with array of strings typescript
const [devices, setDevices] = useState<string[]>([])
react typescript usestate array
interface PersonProps {
name: string;
age: number;
hobbies: Array<string>;
isCool: boolean;
}
// Boolean type
const [isCool] = React.useState<boolean>(true);
// String type
const [name] = React.useState<string>('Ruben');
// Number type
const [age] = React.useState<number>(28);
// Null or undefined
const [random] = React.useState<null | undefined>();
// Array of string
const [hobbies] = React.useState<Array<string>>(['soccer', 'cooking', 'code']);
// Custom interface
const [person] = React.useState<PersonProps>({
isCool,
name,
age,
hobbies
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us