Tine S Tsengwa
Tine S Tsengwa

Reputation: 144

Dictionary values in React props (Typescript)

Given a component Product with a props interface ProductProps defined:

interface ProductProps {
  name: string,
  price: {
    amount: number,
    currency: string
  }
}

how do I assign the values for price in the component tag i.e. I want something to the effect of:

<Product name="Nice Shoes" price.amount={100} price.currency="$" />

Upvotes: 1

Views: 3069

Answers (1)

Daniel Bellmas
Daniel Bellmas

Reputation: 657

Because price is an object too you could pass like so:

<Product name="Nice Shoes" price={{amount :100, currency:"$"}} />

The first set of parenthesis are for the jsx syntax and the second is for the object itself

Upvotes: 4

Related Questions