Ordering

  • Define styles after the component.

    Why? We use a higher-order component to theme our styles, which is naturally used after the component definition. Passing the styles object directly to this function reduces indirection.

    1. // bad
    2. const styles = {
    3. container: {
    4. display: 'inline-block',
    5. },
    6. };
    7. function MyComponent({ styles }) {
    8. return (
    9. <div {...css(styles.container)}>
    10. Never doubt that a small group of thoughtful, committed citizens can
    11. change the world. Indeed, its the only thing that ever has.
    12. </div>
    13. );
    14. }
    15. export default withStyles(() => styles)(MyComponent);
    16. // good
    17. function MyComponent({ styles }) {
    18. return (
    19. <div {...css(styles.container)}>
    20. Never doubt that a small group of thoughtful, committed citizens can
    21. change the world. Indeed, its the only thing that ever has.
    22. </div>
    23. );
    24. }
    25. export default withStyles(() => ({
    26. container: {
    27. display: 'inline-block',
    28. },
    29. }))(MyComponent);