question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Naming conventions for stateful components

See original GitHub issue

I’m new to React and there’s a lot of new terms etc. I try to do things rights so I try to use your guidelines (thanks for that BTW). Let’s think about a card component. As far as I understand I should split elements in a stateful components and a stateless function. For instance I have a list of drugs (legal drugs, not silkroad V3.0 ^^), I want to display a list of Card so, doing my best to follow good patterns, I have a stateless function :

export default function Card(props) {
  return (
    <div className="drug-card card hoverable">
{/*Here goes my HTML*/}
    </div>
  );
}

Plus a component with all logic (subscribe to data, states etc.) whereas stateless function only cares about props it receives from the stateful component. Am I right ? Let’s assume than yes for now. Here’s my question : where should I put, or at least where do you put, the stateful components and the stateless function. In the same file, in the same folder, with different names for each files : Index.jsx for the stateless component and Container.jsx for the stateful component.

Is this a good pattern for example ?

image

I hope I didn’t irritate you with what’s is very probably noob questions but the React land is new for me.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
ljharbcommented, Feb 27, 2017

We currently use Aphrodite for CSS. https://github.com/airbnb/javascript/tree/master/css-in-javascript may be helpful here.

(I’m going to close this issue but feel free to keep discussing)

1reaction
ilan-schemoulcommented, Feb 27, 2017

Okay. Another unrelated question (sorry for polluting this thread) what do you use for css with react ? Inline css, modulus css or like me you have a less/sass file in the folder along with components ? Because I’ve been reading a lot of things about styling react components but your opinion, at Airbnb but especially yours, matters a lot for me and a lot of devs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stateful and Stateless Components in React
Stateful and stateless components have many different names. They are also known as: – Container vs Presentational components. – Smart vs Dumb ...
Read more >
Five best practices for React developers - Educative.io
There are three main naming conventions in React that should be considered best practice. ... Elements that need keys should be unique, non-random ......
Read more >
Naming Conventions · Styleguide JavaScript
The name of the file and the folder of components should exactly (case sensitive) match the name of the main (exported) component using...
Read more >
React components naming convention ⚛️ | by Charly Poly
making component easy to find (file name coherence). Here how our naming convention works (well). The convention. [Domain]|[Page/Context]|ComponentName|[Type].
Read more >
Is there an official style guide or naming convention for React ...
Just to add my two cents. As others have stated, file structure is unopinionated. However, component naming is not.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found