重构此反应组件并保持干燥的最佳方法是什么?
我一直在试图重构这种反应组件,并考虑保持干燥的方法(不要重复自己)。那么,重构此反应组件并保持干燥的最佳方法是什么?
I have been trying to refactor this React component and thinking of ways to keep it DRY (don't repeat yourself). So what would be the best way to refactor this React component and keep it DRY?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您为什么认为该组件不是干?如果您的组件(例如
scheduletimetextspan
)为stypled-components
(这是我的假设),那么它们只是带有预填充样式的HTML元素,因此可以重复它们。唯一可以帮助您干的唯一组件可能是对代码部分进行重构:重复的代码部分,将其重复为自我组件:
然后调用:
&lt; timmentDue content = {{ content} /&gt; < /code>
这将保存一些文本行。
Why do you think the component is not DRY? If your components like
ScheduleTimeTextSpan
arestyled-components
(which is my assumption) then they are just HTML elements with prefilled styles so it is okay to repeat them. The only thing that might help you DRY a little bit the component might be refactoring the code sections like:which are repeated, to a self component:
and then calling:
<AppointmentDue content={content} />
This will save some lines of text.