Skip to content

What's the naming convention for local components? #172

@Sam-Kruglov

Description

@Sam-Kruglov

What if I have a LocalComponent that's not intended for use outside of MyComponent - how do I name CSS classes? Would that be ok?

export default function MyComponent(..) {
  return <MyComponent className="MyComponent">
  <ul className="MyComponent-localComponents"> ----- plural name for the descendant
     <LocalComponent/> -- for loop here
  </ul>
</MyComponent>
}

function LocalComponent(..) {
  // can't use "LocalComponent" because that's ambiguous
  // could use MyComponentLocalComponent but that's too long 
  return <li className="MyComponent_LocalComponent">
  <AnotherLocalComponentInfo/>
  <form className="MyComponent_LocalComponent-form">...</form>
</li>
}

function AnotherLocalComponentInfo(..) {
  return <div className="MyComponent_LocalComponent_AnotherLocalComponentInfo">
  <Image className="MyComponent_LocalComponent_AnotherLocalComponentInfo-logo"/>
  ...
</div>

I'm using the underscored name for the descendant but I have to overwrite the Stylelint regexp:

componentName: /^[A-Z][a-zA-Z0-9]+$/,

to ^[A-Z][a-zA-Z0-9]+(_[A-Z][a-zA-Z0-9]+)*$

It feels a little off but I think it's ok. I didn't find any docs on that use case, just wanted to confirm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions