erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
11.99k stars 2.5k forks source link

Moving to Functional React Components #920

Open collinglass opened 8 years ago

collinglass commented 8 years ago

I recently read this article by Cam Jackson. It describes using functions for react components.

Is there any desire to move to this approach? How would one use the connect and connectData decorators?

mmahalwy commented 8 years ago

I think you mean React elements? Thats what those functions are. They are stateless and immutable virtual DOM representation. See: http://stackoverflow.com/questions/30971395/difference-between-react-component-and-react-element

collinglass commented 8 years ago

No. From the article I linked:

"React 0.14 introduced a new syntax for defining components, as functions of props:

const MyComponent = props => (
  <div className={props.className}/>
);

This is by far my favourite method for defining React components..."

And then I see people adding propTypes like so:

MyComponent.propTypes = {
 className: PropTypes.string
}
jaraquistain commented 8 years ago

+1 I'm heavily in favor of this being the standard for presentational components.

janhoogeveen commented 8 years ago

How would one use the connect and connectData decorators?

I think this would make it clear that you have to connect your data in smart components and pass everything as props to your dumb components. By looking at the code you can instantly see if a component is meant to be a dumb component or a smart one. I'd say keep the ES2015 style for smart components and use stateless functional components for dumb ones.