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.js 消えるライフサイクルメソッドについて
Search
takf
October 10, 2019
Programming
160
0
Share
React.js 消えるライフサイクルメソッドについて
takf
October 10, 2019
More Decks by takf
See All by takf
Denoに入門していきなりAleph.jsを触ってみた
takfjp
0
540
Atomic Design とテストの○○な話
takfjp
2
1.9k
Node.jsのアップグレードで気をつけたこと
takfjp
1
2.9k
FARM スタックに触れてみる
takfjp
0
1.7k
React Testing Library の Query について整理してみた
takfjp
0
540
Laravel 初めての業務で遭遇したハマりポイント×2
takfjp
2
3.2k
React で Stateless Functional Component の書き方を盛大に間違えていた話
takfjp
0
450
職歴1年目のフロントエンドエンジニアが インプットとアウトプットに苦しんだ話
takfjp
0
360
meguro.es.pdf
takfjp
0
150
Other Decks in Programming
See All in Programming
Hive Metastoreを通して学ぶIceberg REST Catalog ― 仕様から実装まで
okumin
0
240
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
750
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
190
iOS26時代の新規アプリ開発
yuukiw00w
0
160
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
280
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
260
【ディップ|26年新卒研修資料】TDD実装演習
dip_tech
PRO
0
300
Agentic UI beyond Chats Architecture Patterns & Open Standards @ngMunich 05/2026
manfredsteyer
PRO
0
130
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
160
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
6
6k
【ディップ|26年新卒研修資料】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
270
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
160
Featured
See All Featured
Skip the Path - Find Your Career Trail
mkilby
1
120
RailsConf 2023
tenderlove
30
1.4k
Exploring anti-patterns in Rails
aemeredith
3
360
Leo the Paperboy
mayatellez
7
1.8k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
830
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Side Projects
sachag
455
43k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
200
Being A Developer After 40
akosma
91
590k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Transcript
React.js 消えるライフサイクルメソッドについて Misoca 秋のLT大会 2019.10.10
登壇者について furuichi (@takfjp) 株式会社カオナビ所属 主にフロントエンド(React)の開発に携わっています
https://corp.kaonavi.jp/recruit/
Reactのバージョンアップでこれから消えるライフサイクル メソッドについてお話しします ・現在のReactのバージョン v16.10.0 Released! (2019/10現在) ・v17 の登場はまだ未定
これまでの主な Breaking Changes v16.3 (2018/03) - New Context API, 新しいライフサイクルメソッド追加
- getDerivedStateFromProps - getSnapshotBeforeUpdate v16.8 (2019/02) - React Hooks が追加! - -> 関数コンポーネントが State を持てるように
目覚ましい進歩と その裏で消えゆく者たち・・・
componentWillMount componentWillRecieveProps componentWillUpdate 消える(予定)ライフサイクルメソッド
componentWillMount -> UNSAFE_componentWillMount componentWillRecieveProps -> UNSAFE_componentWillRecieveProps componentWillUpdate -> UNSAFE_componentWillUpdate v16.9
より接頭辞 UNSAFE_ がないと warning v17 で完全に削除 (後方互換性なし) -> 接頭辞つきであればであればv17でも動作 ??
componentWillUnmount 消えずに残る者 まだまだ現役じゃぞい
- v17 より非同期レンダリングを正式にサポート - React Fiber (コアエンジン)が差分の整合性を保つため - componentWillHoge が何度も呼ばれる
(render() が何度も実 行されてしまう) ことで DOM の整合性が危うくなる なぜ消える?
- 今後も残るライフサイクルメソッドに置き換え - componentWillRecieveProps -> componentDidUpdate など - getDerivedStateFromProps も置き換え策
- 公式曰く「まれなライフサイクルメソッド」らしい … - ライフサイクルメソッドに依存しない実装 - componentWillMount 内の処理をconstructorに移すなど 対策 (1)
リファクタのコストが高い場合: ❯ npx react-codemod rename-unsafe-lifecycles <path> https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles 対策 (2)
コマンドラインからファイルを指定 -> 廃止予定のメソッド名を自動的に UNSAFE_xxx に置換
Thank you!