Styling in stateless UI components

Keep styles separated from the parts of the app that are tied to state.
That means routes, views, containers, forms, layouts, etc. should not have any styling or classes in them.
Instead, these heavy-lifting components should be composed of primarily stateless functional UI components.

Form component (with no styles/classNames) - just pure composed components

  1. class SampleComponent extends Component {
  2. render() {
  3. return (
  4. <form onSubmit={this.handleSubmit}>
  5. <Heading children='Sign In'/>
  6. <Input
  7. name='username'
  8. value={username}
  9. onChange={this.handleChange}/>
  10. <Input
  11. type='password'
  12. name='password'
  13. value={password}
  14. onChange={this.handleChange}/>
  15. <Button
  16. type='submit'
  17. children='Sign In'/>
  18. </form>
  19. )
  20. }
  21. }
  22. // Presentational component (with Styles)
  23. const Button = ({
  24. ...props
  25. }) => {
  26. const sx = {
  27. fontFamily: 'inherit',
  28. fontSize: 'inherit',
  29. fontWeight: 'bold',
  30. textDecoration: 'none',
  31. display: 'inline-block',
  32. margin: 0,
  33. paddingTop: 8,
  34. paddingBottom: 8,
  35. paddingLeft: 16,
  36. paddingRight: 16,
  37. border: 0,
  38. color: 'white',
  39. backgroundColor: 'blue',
  40. WebkitAppearance: 'none',
  41. MozAppearance: 'none'
  42. }
  43. return (
  44. <button {...props} style={sx}/>
  45. )
  46. }