Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
EmotionでReactをstylingすればモテるかもしれない
Search
Matsuo Obu
May 29, 2019
Technology
0
610
EmotionでReactをstylingすればモテるかもしれない
Emotion使うとモテるかもしれないという話。React LT会 @Informetis (2019-05-29) で発表。
Matsuo Obu
May 29, 2019
Tweet
Share
More Decks by Matsuo Obu
See All by Matsuo Obu
Reactの歴史
mqtsuo02
0
1k
文学作品「檸檬」をReactで読む
mqtsuo02
1
500
僕が求めていたのはNext.jsだったんだ
mqtsuo02
0
680
Repro Tech Hands-on : Nuxt.js
mqtsuo02
1
900
ピピピのPWA
mqtsuo02
0
720
GraphQLについての5分間
mqtsuo02
0
800
Create React App 読解特急
mqtsuo02
0
100
JekyllとBootstrapを使って静的なブログを作ってみたよ
mqtsuo02
0
83
Other Decks in Technology
See All in Technology
Fashion×AI「似合う」を届けるためのWEARのAI戦略
zozotech
PRO
2
1.1k
ExpoのインダストリーブースでみたAWSが見せる製造業の未来
hamadakoji
0
190
通勤手当申請チェックエージェント開発のリアル
whisaiyo
3
370
ハッカソンから社内プロダクトへ AIエージェント「ko☆shi」開発で学んだ4つの重要要素
sonoda_mj
6
1.4k
半年で、AIゼロ知識から AI中心開発組織の変革担当に至るまで
rfdnxbro
0
120
MySQLとPostgreSQLのコレーション / Collation of MySQL and PostgreSQL
tmtms
1
1.1k
特別捜査官等研修会
nomizone
0
530
なぜ あなたはそんなに re:Invent に行くのか?
miu_crescent
PRO
0
130
Strands AgentsとNova 2 SonicでS2Sを実践してみた
yama3133
1
1.6k
AWSに革命を起こすかもしれない新サービス・アップデートについてのお話
yama3133
0
470
松尾研LLM講座2025 応用編Day3「軽量化」 講義資料
aratako
0
210
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
370
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
23
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
Leadership Guide Workshop - DevTernity 2021
reverentgeek
0
160
Believing is Seeing
oripsolob
0
15
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
84
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
89
Evolving SEO for Evolving Search Engines
ryanjones
0
73
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.1k
Transcript
@mqtsuo02 2019-05-29 React LT会 EmotionでReactをstylingすれば モテるかもしれない
自己紹介 - フリーランスのWebエンジニア - 直近2年間はずっとReactメイン - ReactのSPA3本、ReactNative1本やった - 最近はNext.jsとGAEが好き
Reactでstylingといえば....
いろいろあるけど...
None
ですが...
こんなやつもいます...
自己紹介 - CSS in JS のライブラリ - 高性能:パフォーマンスがいい - 多機能:色々な方法でstylingできる
- 大人気:★ 8,000 over - とてもエモーショナルなロゴですね emotion-js / emotion
多機能な点において styled-componentsに完全勝利
Emotionのstyling いろいろ - css prop (Object styles) - css prop
(String styles) - Styled Components (String styles) - Styled Components (Object styles)
css prop (Object styles) const textStyle = { color: "red"
}; const Page = () => ( <div css={textStyle}>Emotion でモテモテ</div> ); Inline stylesと同じ要領のstyling cssプロパティに指定する
@emotion/coreのcss関数を使うと CSSと同じように書ける css prop (String styles) import { css }
from "@emotion/core" ; const textStyle = css` color: blue; `; const Page = () => ( <div css={textStyle}>Emotion でモテモテ</div> );
styleの共通化はこんな感じに書ける const baseStyleSt = css` color: black; `; const textStyleSt
= css` ${baseStyleSt}; font-size: .8rem; color: blue; `; const baseStyleOb = { color: "black", }; const textStyleOb = { ...baseStyleOb, fontSize: ".8rem", color: "blue", }; String Styles Object Styles
Styled Components (String styles) styled-componentsと同じ要領で書ける import styled from "@emotion/styled" ;
const MoteText = styled.div` color: yellow; `; const Page = () => ( <MoteText>Emotionでモテモテ</MoteText> );
Styled Components (Object styles) import styled from "@emotion/styled" ; const
MoteText = styled.div({ color: "green", }); const Page = () => ( <MoteText>Emotionでモテモテ</MoteText> ); styled-componentsと同じ要領で書ける
$ npm install --save @emotion/core 導入方法 (css props) /** @jsx
jsx */ import { jsx, css } from "@emotion/core" ; @emotion/core パッケージをインストール 各ページファイルでプラグマを書いて Reactの代わりに jsx モジュールをimportする
$ npm install --save @emotion/styled 導入方法 (Styled Components) import React
from "react"; import styled from "@emotion/styled" ; @emotion/styled パッケージをインストール styledだけを使う場合は、プラグマは必要なし styled-components と同じ使用感
Emotionは他にもいろいろな機能がある - Globalコンポーネントでglobalのstylingができる - ネストされてるelementに対してもstylingできる - propsの値から動的なstylingもできる - 姉妹パッケージのfacepaintでメディアクエリをいい感じに書ける -
TypeScriptの型定義がパッケージに入っているのでtsxへの導入も楽
Emotionはこんな人にオススメかもしれない - stylingをとことんカスタムしたい人 - Inline Stylesっぽい感じでclassによるstylingがしたい人 - 環境整備だけして、styling方法は後で考えたい人 - とりあえずナウいパッケージ使いたい人
そうゆうことだ
ReactやってるならEmotionもさわった方がいい プラグマはうざいけど、多機能なのはいい 個人的にはこのロゴ(絵文字)好き Reactのお仕事おまちしてます! このLTで伝えたかったこと
E N D