我知道在 React 中可以對 props 使用解構。但是,我可以使用解構AND道具嗎?所以我有一些確定的輸入,還有一些我通過道具訪問的附加輸入
例子
這是預期的輸出。所以我可以直接使用name和age,其他的都可以通過props eG *props.lastName;
const ExampleComponent : React.FC<{name: string, age:number}> = ({name, age}, props) => {
// do something
}
這可能嗎?如果是,如何?
uj5u.com熱心網友回復:
你可以這樣做:
const ExampleComponent: React.FC<{ name: string; age: number }> = ({
name,
age,
...props
}) => {
// do something
};
這也適用于打字稿。您只需鍵入檢查姓名和年齡即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/373504.html
標籤:javascript 反应 打字稿 解构
