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のいいなと思ったところ
Search
Natsuki
January 15, 2025
1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactのいいなと思ったところ
クラスメソッドのReact事情大公開スペシャル#6
https://classmethod.connpass.com/event/339885/presentation/
Natsuki
January 15, 2025
More Decks by Natsuki
See All by Natsuki
PHPStanのエラーをprettyにしようとしている
natsukiengr
0
42
jsが型安全になったっていい
natsukiengr
0
230
PHPStanをチームに内緒で開発に取り入れる方法
natsukiengr
1
1.9k
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
560
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Side Projects
sachag
456
43k
Automating Front-end Workflow
addyosmani
1370
210k
Statistics for Hackers
jakevdp
799
230k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
890
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
610
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
sira's awesome portfolio website redesign presentation
elsirapls
0
490
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Transcript
Reactのいいなと思ったところ Natsuki
今日話すこと 普段の業務ではVueを使用していて、最近Reactも業務外で勉強し始めました 初心者の目線で「Reactのココいいな」と思った点を共有したいと思います 自己紹介 Natsuki 普段はLaravel + Vueで開発
宣伝 Reactを学ぶ上で、VSCodeの拡張機能を作ってみました。 Your Themes
demo https://github.com/natsuki-engr/your-themes/blob/a1ce518a99009fd5baf489e592958c3c35b5dfcf/img/demo.gif
本題 「Reactのいいなと思ったところ」
dangerouslySetInnerHtml タグを含んだ文字列をHTMLタグとしてレンダリングしたい場合の`setInnerHtml`と同じ XSS攻撃の危険性があるので、注意が必要 「危険なんだぞ」という強い警告を感じるところがいい vueだと v-html で同じ実装ができるが、罪悪感が無い const markup =
'<p>some raw html</p>'; return <div dangerouslySetInnerHTML={{__html: markup}} />; ` ` <script setup> const markup = '<p>some raw html</p>' </script>
一貫してJS 「JSを知っていれば大体書ける」 たとえばJSX
JSX JSXの構成はJSとタグなので、テンプレートのために必要な知識が少ない JSのパラダイム/設計を持ち込める if(items.length === 0) { return <p>empty...</p> }
function ItemList({ items: Item[] }) { return ( <ul> {items.map(item => ( <li key={item.id}>{item.name}</li> ))} </ul> ); }
レンダリングの更新が分かりやすい 基本的に、引数やステートが変わって再レンダリングされるときに 「全て再計算される」と思っておいて、 ・特定の再計算をスキップしたければ useMemo 配列から値の検索とか ・特定の処理をスキップしたければ useEffect APIの呼び出しとか `
` ` `
useEffect/useMemo の悪い例 不要な useEffect 不要な useMemo https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state ` ` function
Form() { const [firstName, setFirstName] = useState('Taylor'); const [lastName, setLastName] = useState('Swift'); const [fullName, setFullName] = useState(''); useEffect(() => { setFullName(firstName + ' ' + lastName); }, [firstName, lastName]); return /** ... */ } ` ` function Form() { const [firstName, setFirstName] = useState("Taylor"); const [lastName, setLastName] = useState("Swift"); const fullName = useMemo( () => firstName + " " + lastName, [firstName, lastName] ); return; /** ... */ } const fullName = firstName + " " + lastName
なぜ今日この話をしようと思ったか
参考 【React】誤解される useMemo と 誤用される useState ―― 「A の変更に反応して B
の値が変わる」と考え るべきでない https://qiita.com/honey32/items/58e56e407d4d87e294a4 【React】useEffect の標準動作は「依存配列の中身が変わると実行」ではない https://qiita.com/honey32/items/62edf5165aced7d0c4bf useState + useEffect -> 再レンダリング中に毎回計算 (重ければ useMemo) https://scrapbox.io/honey32/useState_+_useEffect_->_再レンダリング中に毎回計算_(重ければ_useMemo) props または state に基づいて state を更新する - そのエフェクトは不要かも https://ja.react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state