在React中不处理可重复使用的组件

发布于 2025-01-29 16:44:47 字数 274 浏览 3 评论 0原文

我正在努力遵循重复组件的反应哲学。

我有三个屏幕(Screen1,Screen2)用作我的应用程序沿不同页面的选项卡(Page1,page2),但是每个页面都不相同,它们在标签,按钮等文本中略有不同他们有。并且有一个组件,一个面板,可以在特定页面的所有屏幕中共享。

我应该为每个页面创建每个屏幕作为不同的组件吗?导致4个屏幕组件(第1页的两个,第2页)?如果是,我是否应该在与常规组件文件夹不同的文件夹中定义它们?因为它们不会重复使用。还是我应该创建一个可重复使用的组件并传递给它应该显示为JSON的数据?

I'm struggling with following the React philosophy of reusing components.

I have three screens (Screen1, Screen2) that are used as tabs in different pages along my application (Page1, Page2), but these screens are not the same for each page, they differ slightly in the text of labels, buttons, etc that they have. And there is a component, a panel, that is shared among all the screens of a certain page.

Should I create each screen as a different component for each page? Resulting in 4 screen components (two for Page1 and two for Page2)? If yes, should I define them in a different folder than the regular components folder? Because they wouldn't be reusable. Or should I create a reusable component and pass to it the data it should display as json for e.g.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深已缘浅 2025-02-05 16:44:47

“我应该将其作为组成部分提取吗?”的问题。太情境了,无法回答。因此,这取决于:

  • 您将复制几次非常相似的代码?
  • 他们将来会分开改变吗?他们的要求有所不同吗?
  • 当您组合它们时,提取的可重复使用的组件会变得非常长/复杂吗?

这些是您需要回答的问题。

The question of "Should I extract this as a Component?" is too situational to answer. So it depends on:

  • How many times will you copy-paste very similar code?
  • Will they change separately in future? Are their requirements different?
  • Does the extracted reusable component become extremely long/complex when you combine them?

These are the questions you need to answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文