Component not render correctly using only emotion CSS props
See original GitHub issueBug Report
Given the following basic component code
// @flow
import React from 'react'
import { css } from '@emotion/core'
const base = css`
color: red;
`
export const Button = ({ children }) => <button css={base}>{children}</button>
.babelrc
{
"presets": ["@babel/preset-flow", "@emotion/babel-preset-css-prop"]
}
Expected behavior
It should render a button with red color on it. But instead the css is not loaded correctly
Additional context/Screenshots
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
emotion css feature is not rendering the styles (React)
I can create a styled component and use it. However, if I try to use the native css`` feature it renders the object...
Read more >The css Prop
The primary way to style elements with emotion is the css prop. It provides a concise and flexible API to style your components....
Read more >How to Make a List Component with Emotion
This looks pretty weird to me because, not only are we writing styles for the ... to make sure your component is rendering...
Read more >Frequently Asked Questions - Material UI
As a rule of thumb, only use inline-styles for dynamic style properties. ... All MUI components that should render something in the DOM...
Read more >The best styling options for Next.js
As a result, you can start writing CSS right away with no setup required. ... styles/globals.css' function MyApp({ Component, pageProps }) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem and @mitchellhamilton one of the maintainer of Emotion helped me.
Docz appends its babel preset to the user provided config so since its babel preset includes @babel/preset-react which includes the react jsx transform which @emotion/babel-preset-css-prop also uses. So Docz’s usage of the react JSX transform is used by default.
To fix this, we’re including the JSX transform plugin in the plugins in our doczrc.js file. This works because plugins in the config take precedence over plugins in presets.
Credits to @mitchellhamilton
I’m getting issue with both the pragma and the babel preset – my issue seems to be that I’m using TypeScript, since it works fine for me just using .js files. If it helps, I can set up a demo repo.