Created
June 11, 2017 21:53
-
-
Save tkh44/9f5e7afc2effcff507a609cebb14040a to your computer and use it in GitHub Desktop.
steps emotion takes to work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // original code | |
| styled.h1`color:${myColor};` | |
| // Step 1 | |
| // emotion creates a function call from | |
| // tagged template expression | |
| styled('h1', css`color:${myColor};`) | |
| // Step 2 | |
| // glam converts the tagged template expression to a | |
| // function call and creates className, stylesheets, and vars | |
| styled('h1', css('css-12345', [myColor])) | |
| // Step 3 | |
| // emotion pulls the args out and gives them to | |
| // the `styled` higher order component | |
| styled('h1', ['css-12345', [myColor]]) | |
| // Step 4 (only step that occurs on the client) | |
| // in styled we call the css function from step 2 ourselves | |
| // this allows us to evaluate any ${props => ...} values | |
| const myFinalClassName = props.className + ' ' + css('css-12345', [myColor]) | |
| return createElement('h1', { className: myFinalClassName, ...props }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment