If I install emotion/css
then the API is nice and clear:
package.json:
"dependencies": {
"@emotion/css": "^11.1.3",
React component:
import React from "react";
import { css } from "@emotion/css";
const someStyle = css`
display: none;
`
function MyComponent() {
return (
<div className={someStyle} />
);
}
However according to the docs you should install @emotion/react
:
https://emotion.sh/docs/introduction
package.json:
"dependencies": {
"@emotion/react": "^11.4.1",
Now the API is a lot more messy:
import React from "react";
/** @jsx jsx */
import { jsx, css } from "@emotion/react";
const someStyle = css`
display: none;
`;
function MyComponent() {
return (
<div css={someStyle} />
);
}
Not only do you need a comment /** @jsx jsx */
, but you also have to import jsx
even though it's not used. In my IDE this means I get a lint warning by my React import.
What is the benefit of the recommended way? Im tempted to ignore the documentation and do it the old way.