Inline

  • Use inline styles for styles that have a high cardinality (e.g. uses the value of a prop) and not for styles that have a low cardinality.

    Why? Generating themed stylesheets can be expensive, so they are best for discrete sets of styles.

    1. // bad
    2. export default function MyComponent({ spacing }) {
    3. return (
    4. <div style={{ display: 'table', margin: spacing }} />
    5. );
    6. }
    7. // good
    8. function MyComponent({ styles, spacing }) {
    9. return (
    10. <div {...css(styles.periodic, { margin: spacing })} />
    11. );
    12. }
    13. export default withStyles(() => ({
    14. periodic: {
    15. display: 'table',
    16. },
    17. }))(MyComponent);