Answers for "react typescript usestate array"

2

useStae with array of strings typescript

const [devices, setDevices] = useState<string[]>([])
Posted by: Guest on July-27-2020
0

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
});
Posted by: Guest on August-21-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language