Reputation: 235
I know that it´s possible to use destructuring for props in React. However, can I use destructuring AND props? So that I have some determined inputs and also some addtional ones that I access via props
Example
This is the expected output. So I can use name and age directly, and everything else via props e.G. *props.lastName;
const ExampleComponent : React.FC<{name: string, age:number}> = ({name, age}, props) => {
// do something
}
Is this possible? If yes, how?
Upvotes: 1
Views: 725
Reputation: 294
You can do it like this:
const ExampleComponent: React.FC<{ name: string; age: number }> = ({
name,
age,
...props
}) => {
// do something
};
This works with typescript too. You can just type check name and age.
Upvotes: 4