React Stateless Component - Tuong-Nguyen/JavaScript-Structure GitHub Wiki
- Stateless functional components are useful for dumb/presentation components
- Presentation components focus on the UI rather than behavior
- Get performance benefit
- Don't support state or life cycle method, the state should be managed by other "container" like Redux
Ref: Why should use stateless functional component
- Use arrow function, body of the function is jsx elements
const SkiDayCount = (props) => (<div>{props.title}</div>)
- Instead of the entire
props
object, we can specify what properties we want to use
const SkiDayCount = ({title}) => (<div>{title}</div>)
We use stateless component whenever possible, i.e when we don't need
- State
- Refs
- Lifecycle methods
- Child method (for performance, because we should avoid nested function in stateless component)