Reactjs 反应组件名称,如BEM

Reactjs 反应组件名称,如BEM,reactjs,Reactjs,我得到了一些很好的反馈,这里有一些最佳实践。感谢AirBnB 所以。。。类似于类的边界元法,但用于组件名和子级。有点厌倦了在组件周围搜索 就这样。。组件\uuuu childName\uuuu childName\uuuuu childName.jsx 然而,我有这个想法,我想知道: 这种做法不好吗? 组件名称是否会变得笨拙 当文件名在一个盒子中的盒子在一个盒子中的盒子中时,会将所有文件名链接在一起 可以简略地说: Component__List.jsx Component__List__Ite

我得到了一些很好的反馈,这里有一些最佳实践。感谢AirBnB

所以。。。类似于类的边界元法,但用于组件名和子级。有点厌倦了在组件周围搜索

就这样。。组件\uuuu childName\uuuu childName\uuuuu childName.jsx

然而,我有这个想法,我想知道:

这种做法不好吗? 组件名称是否会变得笨拙

当文件名在一个盒子中的盒子在一个盒子中的盒子中时,会将所有文件名链接在一起

可以简略地说:

Component__List.jsx
Component__List__Item,jsx
更新问题:

为每个组件单独设置一个目录是否有用?我也看到了这一点

例如:

|-Components
|--ExampleComponent
|---Component.jsx
|---ComponentList.jsx
|---ComponentItem.jsx
|---ComponentItemDetail.jsx
|---Component.scss
|--AnotherOne
|---AnotherOne.jsx

等等…

我想你是在要求一个好的命名实践,你可以给你的组件命名为
Component\u User.jsx
,如果它有一个标题,
Component\u User\u header.jsx
,如果标题有一个标签
Component\u User\u header\u label.jsx
。如果你问smtg其他问题,你可以忽略其余的:)

我想更好的方法是将相关组件放入域文件夹:例如在
user
目录下
index.jsx
将是您的主要组件,而
index.css
将是该组件的主要css。然后,您可以为每个子组件创建一个类似的命名文件作为子目录

user // main directory
  image //sub directory
    index.jsx //component file import index.css
    index.css //css for this component
  header
     index.jsx //component file import index.css
     index.css
  index.jsx //main component file import sub-directories index files to use those components
  index.css

你需要把这当作一个问题。不清楚你在问什么。在这里写得很好: