Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
React 19でお手軽にCSS-in-JSを自作する
Search
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
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
5.3k
一億総業務改善を支える社内AIエージェント基盤の要諦
yukukotani
9
3.6k
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
6
2.9k
Scale out your Claude Code ~自社専用Agentで10xする開発プロセス~
yukukotani
11
5.9k
AI Coding Agent Enablement in TypeScript
yukukotani
21
21k
AI Coding Agent Enablement - エージェントを自走させよう
yukukotani
14
8.6k
Expoによるアプリ開発の現在地とReact Server Componentsが切り開く未来
yukukotani
3
950
僕が思い描くTypeScriptの未来を勝手に先取りする
yukukotani
12
3.6k
Web技術を駆使してユーザーの画面を「録画」する
yukukotani
15
8.3k
Other Decks in Programming
See All in Programming
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
580
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
280
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
770
ALB ログから Trace を気合で繋げる技術
fohte
7
820
Flow は今どうなっているか
mizdra
PRO
0
800
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
600
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
120
高専キャリア LT 発表内容
crysta1221
6
5.3k
バグを直したら useEffect が消えた
colorful12
3
780
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
130
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
360
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
280
The Art of Programming - Codeland 2020
erikaheidi
57
14k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Code Review Best Practice
trishagee
74
20k
KATA
mclloyd
PRO
35
15k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
550
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
680
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The Cult of Friendly URLs
andyhume
79
7k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
240
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つになった
ありがとうございました このテクを使ったライブラリを作ったので使ってね