DEV Community

Discussion on: React Beginner Question Thread ⚛

Collapse
 
lith_light_g profile image
lith

How do you structure a container component in a React app that uses local state (no Redux)? Do you create a HOC for it?

Collapse
 
rajington profile image
Raj Nigam

Definitely check out github.com/acdlite/recompose/blob/... if you're into keeping everything an SFC, especially check out withStateHandlers.

Collapse
 
dan_abramov profile image
Dan Abramov

I don’t quite understand the question. I think people take the distinction between “presentational” and “container” components waaaay too seriously. When I wrote an article about them I mentioned this is a pattern I noticed organically in a codebase, not a set of rules to follow.

If I were writing a component I wouldn’t think about whether it’s a “container” at all. I’d just write a component. It might use local state, or it might not. That doesn’t really matter to me. Later, I might split it into a few components, or I might actually “inline” it into a larger component if I realize it was extracted prematurely.

I would definitely not create HOCs except for very rare cases where a single HOC is useful across many many components. I would never create a HOC only for one component to use it.