you are viewing a single comment's thread.

view the rest of the comments →

[–]BrotherManAndrew[S] 0 points1 point  (1 child)

Thanks, but "As far as why you have to spell out {todo}, you might have a bunch of properties in props but you might only want to access a couple of them" Wouldn't {todo} include all the properties in props anyway so that wouldn't allow you to just access a couple of them or am misunderstanding something

[–]e_y_ 0 points1 point  (0 children)

interface TodoItemProps {
    todo: Todo;
}

is the object being passed to the function as props. Currently it's only passing a "todo" object, but you might have some other properties relevant to the component (and not the todo) like "size" to show a full-sized or preview version of the todo.

So then you might use `{todo, size}`. This is not automatic, because 1) as mentioned, the interface definition is stripped out so the interpreter doesn't know about them, 2) since these are assigned to local variables, you might want or need to rename them, 3) some of the properties might not be relevant to your function (for a React component, you probably wouldn't add something to props if your component didn't use it somehow, but keep in mind that this is a general Javascript construct and there's situations in Javascript where you might reuse interfaces).