#How to destruct nested props with TypeScript

6 messages ยท Page 1 of 1 (latest)

lone moon
#

Here is a link to codesandbox: https://codesandbox.io/s/sparkling-night-3hpnps?file=/src/TestimonialCard.tsx:509-631

1. Can someone help me how to go from this

 <p className="text-xl font-medium tracking-tight text-[#dddddd]">
   {props.testimonial.name}
  </p>

to

 <p className="text-xl font-medium tracking-tight text-[#dddddd]">
   {name}
 </p>
  1. and I want to destruct the name, image, text, position within the props something like:
const TestimonialCard = (props:{testimonial:{name, image, text, position}) => {...}

sparkling-night-3hpnps by wongprom using @typescript-eslint/types, loader-utils, react, react-dom, react-scripts, tailwindcss

#

How to destruct nested props with TypeScript

rocky urchin
#

const TestimonialCard = ({ testimonial }: Props) => {

#

Or const TestimonialCard = ({ testimonial: { name, position, text } }: Props) => { for further destructuring

lone moon
#

Thanks for the super fast replay ๐Ÿš€ ๐Ÿ”ฅ @rocky urchin
I will have a look at it ๐Ÿ‘

#

It was just to copy/paste your snippet and it worked like a charm