技術文章
技術問答
My Project
iT 徵才
聊天室
2026 鐵人賽
登入/註冊
文章
問答
Tag
邦友
鐵人賽
搜尋
2023 iThome 鐵人賽
0
Modern Web
前端知識
系列 第
29
篇
10 React Antipatterns to Avoid - Code This, Not That!
15th鐵人賽
jasonchenchen
2023-10-29 16:55:49
1085 瀏覽
分享至
React Anti-patterns and Solutions
Anti-pattern 1: Big Components
Problem
: Starting off with one big, deeply nested component.
Solution
: Refactor into smaller, reusable components.
Anti-pattern 2: Nesting Components
Problem
: Defining child components inside parent components.
Solution
: Define child components outside the parent component.
Anti-pattern 3: Failure to Memoize
Problem
: Running expensive calculations every time the state changes.
Solution
: Use the `useMemo` hook.
Anti-pattern 4: Useless Divs
Problem
: Wrapping multiple elements in unnecessary `div` tags.
Solution
: Use React Fragments.
Anti-pattern 5: Messy Files
Problem
: Exporting multiple components from a single file.
Solution
: One component per file.
Anti-pattern 6: Big Bundles
Problem
: Slow initial page load due to large JavaScript bundles.
Solution
: Use code splitting and lazy loading.
Anti-pattern 7: Prop Drilling
Problem
: Passing state through multiple layers of components.
Solution
: Use context API for global state management.
Anti-pattern 8: Prop Plowing
Problem
: Components with a lot of different props.
Solution
: Use the spread syntax.
Anti-pattern 9: Messy Event Handlers
Problem
: Using arrow functions for event handlers with multiple arguments.
Solution
: Use curried functions.
Anti-pattern 10: Single Object State
Problem
: Using a single object for all state in a component.
Solution
: Use multiple `useState` hooks, and extract to custom hooks
留言
追蹤
檢舉
上一篇
Better optimistic update
下一篇
ts-reset
系列文
前端知識
共
30
篇
目錄
RSS系列文
訂閱系列文
2
人訂閱
26
Learn React Hooks: useRef - Simply Explained!
27
Next.js 14.0 ( server action )
28
Better optimistic update
29
10 React Antipatterns to Avoid - Code This, Not That!
30
ts-reset
完整目錄
熱門推薦
{{ item.subject }}
{{ item.channelVendor }}
|
{{ item.webinarstarted }}
|
{{ formatDate(item.duration) }}
直播中
立即報名
尚未有邦友留言
立即登入留言
iThome鐵人賽
參賽組數
929
組
團體組數
32
組
累計文章數
14665
篇
完賽人數
176
人
看影片追技術
看更多
{{ item.subject }}
{{ item.channelVendor }}
|
{{ formatDate(item.duration) }}
直播中
熱門tag
15th鐵人賽
16th鐵人賽
13th鐵人賽
17th鐵人賽
14th鐵人賽
12th鐵人賽
18th鐵人賽
11th鐵人賽
鐵人賽
2019鐵人賽
javascript
2018鐵人賽
python
2017鐵人賽
windows
php
c#
linux
windows server
css
熱門問題
「相容 MySQL 協議」的引擎,你們是怎麼做能力偵測的?我們試了 42 種,結論有點慘
本地跑模型做評測,你們是怎麼給 context 長度設上限的?我們沒設,7.1 GB 的模型吃掉了 51 GB
好奇問問各位大大當如果面對上層施壓時,工程師應當如何捍衛自己的工作優先考量權?上層威脅利誘時,又應當如何用溫和不失堅定的語氣讓上司明白自己為什麼這麼做
熱門回答
本地跑模型做評測,你們是怎麼給 context 長度設上限的?我們沒設,7.1 GB 的模型吃掉了 51 GB
好奇問問各位大大當如果面對上層施壓時,工程師應當如何捍衛自己的工作優先考量權?上層威脅利誘時,又應當如何用溫和不失堅定的語氣讓上司明白自己為什麼這麼做
熱門文章
講到 IT 監控,你一定聽過 SolarWinds--但你真的了解它在做些什麼嗎?
乞丐超人我買超市打折便當時突然發現我家社區夜班保全是美國新創CTO後我拜他為師,Day09:這東西這麼陽春,你真的敢拿給客戶用?
Day 13|多開幾個 Subagent,會比較快嗎?
C 槽空間不足,卻找不到大檔案?看看哪些資料夾最佔空間
Day 1|Wazuh 是什麼?認識開源資安監控平台
IT邦幫忙
×
標記使用者
輸入對方的帳號或暱稱
Loading
找不到結果。
標記
{{ result.label }}
{{ result.account }}