0

Why do I have to place {} around my input paramters in typescript, for e.g.

// you can also inline the type declaration; eliminates naming the prop types, but looks repetitive
const App = ({ message }: { message: string }) => <div>{message}</div>;

Instead of simply

const App = (message: string) => <div>{message}</div>;
H4shBrown
  • 1
  • 1
  • 1
    You don't. You could have a single variable for the props argument without de-structuring it. The de-structuring approach is just idiomatic. – Quentin Aug 29 '22 at 15:45
  • Because the props passed to a component are always an object. So if the only thing on that object you care about is `message`, you use object destructuring to pick out that property from the props parameter. (Otherwise, use `props: { message: string; }` and then `props.message` instead of just `message` when using it.) I suggest working through [the tutorial on the React website](https://reactjs.org/tutorial/tutorial.html). – T.J. Crowder Aug 29 '22 at 15:48

0 Answers0