Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs terminology "smart" and "dumb" #170

Closed
ryanflorence opened this issue Oct 30, 2015 · 16 comments · Fixed by #191 or reduxjs/redux#1037
Closed

Docs terminology "smart" and "dumb" #170

ryanflorence opened this issue Oct 30, 2015 · 16 comments · Fixed by #191 or reduxjs/redux#1037

Comments

@ryanflorence
Copy link

I'd love to change the vocabulary to "stateful" and "stateless".

@erikras
Copy link
Contributor

erikras commented Nov 4, 2015

I agree. The smart/dumb dichotomy never really made much sense to me.

Another option would be "connected" and "unconnected", since "state" could be confused with React component state. A component could have React state and not be connect()ed to the Redux store.

@namelos
Copy link

namelos commented Nov 5, 2015

Imo "connected" and "unconnected" would be better, in fact I could write as follow:

const MyComp = ({ myProp, myAction }) => <div>
  <h1>{ myProp }</h1>
  <button onClick={ myAction }>Click Me</button>
</div>

export default connect(
  ({ myReducer }) => ({ myProp: myReducer.myState }),
  dispatch => bindActionCreator({ myAction }, dispatch)
)(MyComp)

It is stateless function component while it was connected to redux, so "stateless" might be kinda confusing.

+1 for "connected" and "unconnected".

@gaearon
Copy link
Contributor

gaearon commented Nov 7, 2015

I'm up for changing it but let's choose terms carefully.

@gaearon
Copy link
Contributor

gaearon commented Nov 7, 2015

“Stateful” and “stateless” is a different, and not necessarily relevant distinction. A component may be stateful (e.g. holding a local form or “dropdown toggled” state) but not aware of Redux.

@gaearon
Copy link
Contributor

gaearon commented Nov 7, 2015

“Connected” and “unconnected” component is closer to the current smart/dumb distinction, but it still has some confusion potential.

const Counter = ({ value, onIncrement }) =>
  <div>{value} <button onClick={onIncrement}>+</button></div>;

export default connect(
  state => state.counter
)(Counter);

Is Counter connected in this example? Seems so. But wait, no, Counter is not connected—it's the component generated by connect() that is connected. We export it so for outside code, Counter export is a connected component, but Counter itself in this source file is not connected per se.

This is why I don't quite like saying “connected”. The argument to connect() is the unconnected component, but the fact that it is passed to connect() makes it natural to assume that is the “connected” component because it is being connected.

@gaearon
Copy link
Contributor

gaearon commented Nov 7, 2015

One way out of this mess is to probably stop calling “dumb” component anything special, and call the “smart” components the container components. This is consistent with Flux and Relay documentation and API.

@ghost
Copy link

ghost commented Nov 7, 2015

Containers, in my mind at least, just click when it comes to understanding the distinction

@ellbee
Copy link
Contributor

ellbee commented Nov 7, 2015

Another vote for container here. As well as being consistent with Relay, the term is also already used in the folder structure of the Redux examples.

@gaearon
Copy link
Contributor

gaearon commented Nov 8, 2015

Khan Academy calls these “logic components” and “presentation components”. This matches what I originally meant by “smart” and “dumb” components (before Redux or support for functional components in React) although I'm not sure I'm fond of these names.

@acdlite
Copy link
Contributor

acdlite commented Nov 8, 2015

Worth mentioning that the Flux website also uses the terms controller-view and view. I actually think those are good descriptors, except they reek of MVC.

@gnoff
Copy link
Contributor

gnoff commented Nov 8, 2015

In my use I've started naming my connected components ThingConnector. If there is concern with renaming 'smart' to 'connected' perhaps 'connector' is a less ambiguous since it is a component which is intended to be connected. I also favor dropping 'dumb' as a descriptor. Every component that isn't a connector is 'dumb' or 'plain' implicitly.

In practice I connect things deeper in my tree and I don't name them al 'Connector' but then I am already eschewing the smart/dumb pattern there anyway

@gnoff
Copy link
Contributor

gnoff commented Nov 8, 2015

For what it's worth I also like calling them container components.

@dvdzkwsk
Copy link

I agree with @gnoff about using the term "container." The terms "smart" and "dumb" definitely get the point across, but "container" is used elsewhere as @gaearon said (I'll throw recompose into the list as well) and does a better job describing the fact that the component is in fact wrapped by a higher-order component.

Personally I think it helps demonstrate the fact that everything is in fact a "dumb" component, but some of those are just wrapped in a container.

@gaearon
Copy link
Contributor

gaearon commented Nov 13, 2015

Presentational Components and Container Components it is.
PRs to update docs here and in Redux docs are welcome.

@mik01aj
Copy link

mik01aj commented Dec 29, 2015

Hey, how about adding a reference to other-names-of-the-same-thing to the docs to avoid further confusion?

Presentational Components Container Components
dumb smart
view controller-view
stateless stateful

@gaearon
Copy link
Contributor

gaearon commented Dec 29, 2015

Happy to accept a PR.

However as I wrote above, presentational components aren't necessarily stateless.
It's just they're not concerned with fetching / retrieving data. But they may have local UI state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants