@emotion/core は @jsx jsx を書かなくても使える、の続き
3887 ワード
問題
emotion v11では上のようにはうまく動かない様子。
解決
-
/** @jsx jsx */
の除去
-
Property 'css' does not exist on type ...
エラーの除去
/** @jsx jsx */
/** @jsx jsx */
の除去Property 'css' does not exist on type ...
エラーの除去/** @jsx jsx */
core->react
$ yarn remove @emotion/core
$ yarn add @emotion/react
$ yarn add -D @emotion/babel-preset-css-prop
.babelrc
{
"presets": ["@emotion/babel-preset-css-prop"]
}
オプション等あるが、基本これだけ。
Property 'css' does not exist on type ...
.d.ts相当のファイル
/// <reference types="@emotion/react/types/css-prop" />
自分はnextjsを使っているので、next-env.d.ts
に追加した。
サンプル
import { css } from "@emotion/react"
import React from "react"
interface Props {}
const test: React.FC<Props> = (props) => {
return (
<div
css={css`
p {
background-color: blueviolet;
}
span {
background-color: burlywood;
}
`}
>
<p>aaaaa</p>
<span>bbbbb</span>
</div>
)
}
export default test
import { css } from "@emotion/react"
import React from "react"
interface Props {}
const test: React.FC<Props> = (props) => {
return (
<div
css={css`
p {
background-color: blueviolet;
}
span {
background-color: burlywood;
}
`}
>
<p>aaaaa</p>
<span>bbbbb</span>
</div>
)
}
export default test
個人的には
import { css } from "@emotion/react"
をしたほうが圧倒的に便利。cssにインテリセンスが効く。
Author And Source
この問題について(@emotion/core は @jsx jsx を書かなくても使える、の続き), 我々は、より多くの情報をここで見つけました https://qiita.com/github0013@github/items/9da0459d82023c0981c8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .