[英]Typescript child has same props as parent, is there a cleaner way to do it?
Quiz question component prop types :测验问题组件道具类型:
type Props = {
question_details: question_details,
handle_back_click: (event: React.MouseEvent<HTMLButtonElement>) => void
handle_next_click: (event: React.MouseEvent<HTMLButtonElement>) => void
question_number:number
}
It renders a child component QuestionButtons like so它像这样呈现一个子组件 QuestionButtons
<QuestionButtons
answer_selected={answer_selected}
handle_back_click={handle_back_click}
handle_next_click={(e)=> handle_next(e)}
question_number={question_number}
/>
Which also has the same props哪个也有同样的道具
type Props = {
answer_selected: string,
handle_back_click: (event: React.MouseEvent<HTMLButtonElement>) => void
handle_next_click: (event: React.MouseEvent<HTMLButtonElement>) => void
question_number:number
}
My question is, is there a cleaner way to do this, so I do not repeat the props, without using redux or moving the QuestionButtons component into the parent quiz question component我的问题是,有没有更简洁的方法来做到这一点,所以我不重复道具,而不使用 redux 或将 QuestionButtons 组件移动到父测验问题组件中
You can pass rest props:您可以传递休息道具:
<QuestionButtons
answer_selected={answer_selected}
{...props}
/>
which props
is those that are same.哪些
props
是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.