1

I need to initialize an array of objects in my state in react Ts. The array should look somewhat like this

  addressBook[
       details{
           name:"Tom"
           mail: "[email protected]"
           mobile: "1111111111"
       }
   ]

I need to create an array of objects like this which will contain multiple contacts with their details.

1 Answer 1

2

Define an interface:

interface Detail {
  name: string;
  mail: string;
  mobile: string;
}

Then in component definition:

const DetailPage = (): ReactElement => {
   const [details, setDetails] = useState<Detail[]>([]);

   return ( . . . );
};
Sign up to request clarification or add additional context in comments.

1 Comment

I need to define it in a state. How would I be doing that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.