Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
React 19でお手軽にCSS-in-JSを自作する
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yuku Kotani
December 30, 2024
Programming
1.1k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React 19でお手軽にCSS-in-JSを自作する
Nihonbashi.js #9
https://nihonbashi-js.connpass.com/event/332328/
Yuku Kotani
December 30, 2024
More Decks by Yuku Kotani
See All by Yuku Kotani
Webとヘルスデータ
yukukotani
1
830
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
4
5.5k
一億総業務改善を支える社内AIエージェント基盤の要諦
yukukotani
9
3.7k
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
6
3k
Scale out your Claude Code ~自社専用Agentで10xする開発プロセス~
yukukotani
11
6k
AI Coding Agent Enablement in TypeScript
yukukotani
21
21k
AI Coding Agent Enablement - エージェントを自走させよう
yukukotani
14
8.7k
Expoによるアプリ開発の現在地とReact Server Componentsが切り開く未来
yukukotani
3
970
僕が思い描くTypeScriptの未来を勝手に先取りする
yukukotani
12
3.6k
Other Decks in Programming
See All in Programming
AWSに止められる覚悟してますか?
morizo_1984
2
510
Verilogで学ぶCPU自作入門.pdf
uyuki234
8
4k
APNsからLive Activityを開始する話
yumnumm
0
150
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
440
The Rails Doctrine Decade
koic
2
490
setup-vp GitLab対応の裏側
naokihaba
0
150
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
230
パーソナライズPodcastを作った話
repunit11
0
120
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
620
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
550
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
520
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
The agentic SEO stack - context over prompts
schlessera
0
960
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
66k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Code Review Best Practice
trishagee
74
20k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
YesSQL, Process and Tooling at Scale
rocio
174
15k
How to make the Groovebox
asonas
2
2.5k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
Transcript
React 19でお手軽に CSS-in-JSを自作する @yukukotani 2024/10/31 - Nihonbashi.js #9
自己紹介 小谷 優空 - @yukukotani ・VP of Technology @ Ubie,
Inc. ・Maintainer of KumaUI ・Student @ Univ. Tsukuba
CSS-in-JS? JavaScriptコード内でCSSも書ける君。Reactでよく使われる 有名どころは styled-components とか emotion とか
作ってみよう
簡単ですね style属性を埋め込むだけの高階関数
嬉しいですね 色がつきました
嬉しくない たくさん描画するとスタイルが重複して、サイズが爆発する
そう簡単には作れない 世の中のCSS-in-JSは色々頑張っていX <head>にstyleを差し込んで参照することで同じスタイルをまとめX → useLayoutEffectを使うのでSSRでは動かない b SSRの描画中に必要なstyleをメモしておいて最後に差し込
フレームワークによっては無駄に2回描画関数が走る
スタイルシート・・・重複・・・? 聞き覚えが・・・?
React 19 で組み込みサポートが拡充 なんか良くなったらしいぞ https://ja.react.dev/blog/2024/04/25/react-19
React 19 で組み込みサポートが拡充 インラインでstyleタグを描画すると href属性をキーとして重複排除しながらheadに差し込んでくれる https://ja.react.dev/reference/react-dom/components/style
作ってみよう style属性の代わりにstyleタグを差し込み、classNameで重複排除&参照 オブジェクトからCSSに変換 インラインstyleタグを差し込む classでスタイルを参照
作ってみよう スタイルシートのハッシュで一意なclassNameを生成 キーをケバブケースにしてるだけ backgroundColor -> background-color
嬉しいね headに1つだけstyleを差し込みclassで参照 重複するスタイル定義がなくなっている React が勝手に head に持っていってくれる 同じクラスを参照するだけ
本当に重複しないかな? スタイルの一部が動的に決まるコンポーネントを考える background-color を プロパティで変える
本当に重複しないかな? プロパティを変えて同時に描画してみる
本当に重複しないかな? `color: red;` が全クラスで重複しちゃうね(涙)
Atomic CSS にする コンポーネントに必要なスタイルを1つのクラスに押し込めるのではなく、 プロパティと値のペアそれぞれで独立したクラスを作る
Atomic CSS にする
嬉しいね `color: red;` が1つになった
ありがとうございました このテクを使ったライブラリを作ったので使ってね