LoginSignup
4
0

More than 1 year has passed since last update.

emotionの型エラーが出たとき・スタイルが反映されないときの対処法

Last updated at Posted at 2021-07-31

バージョン

@emotion/react: 11.4.0

型エラーが出たとき

tsconfig.jsonに以下を追記。

{
  "compilerOptions": {
    //・・・
    "types": ["@emotion/react/types/css-prop"],
   }
}

コンパイルされないとき

emotionのコンパイルはemotion独自のコンパイラを通す必要があるみたいです。

ソースコードの頭で以下の宣言をするとスタイルが効きます

/** @jsxImportSource @emotion/react */ 
import React from "react";
import { css } from "@emotion/react";

const App = () => {
  return (
    <div>
      <p css={css`color: green;`} >hello</p>
     </div>
   )
}

この頭に書いたものを「JSX Pragma」というそうです。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0