Class Names

Edit this page

It can be useful to create a className that is not passed to a component, for example if a component accepts a wrapperClassName prop or similar. To do this, Emotion exposes a render prop component which you can pass a function which accepts css and cx. If you have used versions of Emotion prior to Emotion 10 or used vanilla Emotion, the css and cx functions work exactly like they do in versions.

import { ClassNames } from '@emotion/core'

// this might be a component from npm that accepts a wrapperClassName prop
let SomeComponent = props => (
  <div className={props.wrapperClassName}>
    in the wrapper!
    <div className={props.className}>{props.children}</div>

    {({ css, cx }) => (
        wrapperClassName={css({ color: 'green' })}
          color: hotpink;
        from children!!
in the wrapper!
from children!!