Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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="$" />

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading